DmitrMakeev commited on
Commit
3a385ce
·
verified ·
1 Parent(s): 573cab7

Update webhook_handler.py

Browse files
Files changed (1) hide show
  1. webhook_handler.py +12 -4
webhook_handler.py CHANGED
@@ -88,15 +88,23 @@ def handle_webhook(data, key_callback_vk, db_name, vk_st_alone):
88
  logging.debug(f"Connected to database: {db_name}")
89
 
90
  # Проверяем, существует ли запись для данного пользователя
91
- cursor.execute("SELECT orders FROM contacts WHERE vk_id = ?", (user_id,))
92
  result = cursor.fetchone()
93
  logging.debug(f"Query result for user {user_id}: {result}")
94
 
95
  if result:
96
  # Получаем данные о группе
97
- orders_data = json.loads(result[0]) if result[0] else {}
98
- logging.debug(f"Orders data for user {user_id}: {orders_data}")
99
- group_status = orders_data.get(str(group_id), 'not')
 
 
 
 
 
 
 
 
100
  logging.info(f"Group status for user {user_id} in group {group_id}: {group_status}")
101
 
102
  if group_status == 'yes':
 
88
  logging.debug(f"Connected to database: {db_name}")
89
 
90
  # Проверяем, существует ли запись для данного пользователя
91
+ cursor.execute("SELECT * FROM contacts WHERE vk_id = ?", (user_id,))
92
  result = cursor.fetchone()
93
  logging.debug(f"Query result for user {user_id}: {result}")
94
 
95
  if result:
96
  # Получаем данные о группе
97
+ orders_data = result[17] if result[17] else '{}'
98
+ logging.debug(f"Raw orders data for user {user_id}: {orders_data}")
99
+
100
+ try:
101
+ orders_data_json = json.loads(orders_data)
102
+ logging.debug(f"Parsed orders data for user {user_id}: {orders_data_json}")
103
+ except json.JSONDecodeError as e:
104
+ logging.error(f"Failed to parse JSON for user {user_id}: {e}")
105
+ orders_data_json = {}
106
+
107
+ group_status = orders_data_json.get(str(group_id), 'not')
108
  logging.info(f"Group status for user {user_id} in group {group_id}: {group_status}")
109
 
110
  if group_status == 'yes':