Update app.py
Browse files
app.py
CHANGED
@@ -748,7 +748,6 @@ def update_or_insert_user(db_name, user_data, mapping_template, gog_url):
|
|
748 |
|
749 |
logging.debug(f"Processing user with email: {email}")
|
750 |
|
751 |
-
# Получаем текущее значение из базы данных, если оно существует
|
752 |
cursor.execute("SELECT web_st, ws_st, b_mess FROM contacts WHERE email = ?", (email,))
|
753 |
user = cursor.fetchone()
|
754 |
logging.debug(f"User found: {user}")
|
@@ -756,15 +755,7 @@ def update_or_insert_user(db_name, user_data, mapping_template, gog_url):
|
|
756 |
current_web_st = user[0] if user else None
|
757 |
current_ws_st = user[1] if user else None
|
758 |
current_messages = user[2] if user else ""
|
759 |
-
|
760 |
-
# Преобразование статуса WhatsApp
|
761 |
-
new_ws_st = user_data.get('ws_st', "").strip().upper()
|
762 |
-
if new_ws_st == 'TRUE':
|
763 |
-
new_ws_st = '1'
|
764 |
-
elif new_ws_st == 'FALSE':
|
765 |
-
new_ws_st = '0'
|
766 |
-
else:
|
767 |
-
new_ws_st = "" # Если статус не True и не False, оставляем пустым
|
768 |
|
769 |
transformed_data = {}
|
770 |
for json_key, db_column in mapping_template.items():
|
@@ -779,7 +770,17 @@ def update_or_insert_user(db_name, user_data, mapping_template, gog_url):
|
|
779 |
transformed_data[db_column] = str(value)
|
780 |
logging.debug(f"Transformed data: {transformed_data}")
|
781 |
|
782 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
783 |
if 'phone' in user_data:
|
784 |
phone = user_data['phone']
|
785 |
if phone.startswith('+'):
|
@@ -787,16 +788,18 @@ def update_or_insert_user(db_name, user_data, mapping_template, gog_url):
|
|
787 |
transformed_data['phone'] = phone
|
788 |
logging.debug(f"Transformed data after phone processing: {transformed_data}")
|
789 |
|
|
|
|
|
|
|
|
|
|
|
|
|
790 |
# Увеличиваем значение web_st на 1, если пользователь уже существует в базе данных
|
791 |
if current_web_st is not None and current_web_st != "":
|
792 |
transformed_data['web_st'] = int(current_web_st) + 1
|
793 |
else:
|
794 |
transformed_data['web_st'] = 1
|
795 |
|
796 |
-
# Записываем преобразованное значение ws_st
|
797 |
-
transformed_data['ws_st'] = new_ws_st
|
798 |
-
|
799 |
-
# Обработка сообщений
|
800 |
new_messages = transformed_data.get('b_mess', "")
|
801 |
if current_messages:
|
802 |
transformed_data['b_mess'] = current_messages + "; " + new_messages
|
|
|
748 |
|
749 |
logging.debug(f"Processing user with email: {email}")
|
750 |
|
|
|
751 |
cursor.execute("SELECT web_st, ws_st, b_mess FROM contacts WHERE email = ?", (email,))
|
752 |
user = cursor.fetchone()
|
753 |
logging.debug(f"User found: {user}")
|
|
|
755 |
current_web_st = user[0] if user else None
|
756 |
current_ws_st = user[1] if user else None
|
757 |
current_messages = user[2] if user else ""
|
758 |
+
logging.debug(f"Current web_st: {current_web_st}, current_ws_st: {current_ws_st}, current_messages: {current_messages}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
759 |
|
760 |
transformed_data = {}
|
761 |
for json_key, db_column in mapping_template.items():
|
|
|
770 |
transformed_data[db_column] = str(value)
|
771 |
logging.debug(f"Transformed data: {transformed_data}")
|
772 |
|
773 |
+
required_fields = [
|
774 |
+
"vk_id", "chat_id", "ws_st", "ws_stop", "web_st", "fin_prog",
|
775 |
+
"b_city", "b_fin", "b_ban", "b_ign", "b_baners", "b_butt", "b_mess",
|
776 |
+
"shop_st", "curator", "pr1", "pr2", "pr3", "pr4", "pr5", "gc_url",
|
777 |
+
"key_pr", "n_con", "canal", "data_t", 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'
|
778 |
+
]
|
779 |
+
for field in required_fields:
|
780 |
+
if field not in transformed_data:
|
781 |
+
transformed_data[field] = ""
|
782 |
+
logging.debug(f"Transformed data after adding required fields: {transformed_data}")
|
783 |
+
|
784 |
if 'phone' in user_data:
|
785 |
phone = user_data['phone']
|
786 |
if phone.startswith('+'):
|
|
|
788 |
transformed_data['phone'] = phone
|
789 |
logging.debug(f"Transformed data after phone processing: {transformed_data}")
|
790 |
|
791 |
+
# Проверяем наличие ws_st в базе данных и не перезаписываем его, если оно уже существует
|
792 |
+
if current_ws_st is not None and current_ws_st != "":
|
793 |
+
transformed_data['ws_st'] = current_ws_st
|
794 |
+
else:
|
795 |
+
transformed_data['ws_st'] = user_data.get('ws_st', "")
|
796 |
+
|
797 |
# Увеличиваем значение web_st на 1, если пользователь уже существует в базе данных
|
798 |
if current_web_st is not None and current_web_st != "":
|
799 |
transformed_data['web_st'] = int(current_web_st) + 1
|
800 |
else:
|
801 |
transformed_data['web_st'] = 1
|
802 |
|
|
|
|
|
|
|
|
|
803 |
new_messages = transformed_data.get('b_mess', "")
|
804 |
if current_messages:
|
805 |
transformed_data['b_mess'] = current_messages + "; " + new_messages
|