DmitrMakeev
commited on
Commit
•
43306ab
1
Parent(s):
5227ad9
Update app.py
Browse files
app.py
CHANGED
@@ -809,16 +809,10 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
809 |
# Обновление значения web_st
|
810 |
cursor.execute("UPDATE contacts SET web_st = ? WHERE email = ?", (web_st_value, email))
|
811 |
conn.commit()
|
812 |
-
conn.close()
|
813 |
logging.debug(f"User {email} web_st updated to {web_st_value}")
|
814 |
else:
|
815 |
-
conn.close()
|
816 |
logging.debug(f"User {email} not found, proceeding with insert")
|
817 |
|
818 |
-
# Открываем соединение снова для остальных операций
|
819 |
-
conn = sqlite3.connect(db_name)
|
820 |
-
cursor = conn.cursor()
|
821 |
-
|
822 |
# Преобразование данных пользователя на основе шаблона сопоставления
|
823 |
transformed_data = {}
|
824 |
for json_key, db_column in mapping_template.items():
|
@@ -852,9 +846,6 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
852 |
# Добавление значения web_st в данные для вставки
|
853 |
transformed_data['web_st'] = web_st_value
|
854 |
|
855 |
-
# Добавление сообщений в данные для вставки
|
856 |
-
transformed_data['messages'] = json.dumps(user_data.get('messages', []))
|
857 |
-
|
858 |
# Обновление данных пользователя в базе данных
|
859 |
if user:
|
860 |
update_query = "UPDATE contacts SET "
|
@@ -878,7 +869,6 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
878 |
conn.commit()
|
879 |
conn.close()
|
880 |
logging.debug(f"User with email {email} processed successfully")
|
881 |
-
|
882 |
@app.route('/send_get_request', methods=['GET'])
|
883 |
def send_get_request():
|
884 |
token = request.args.get('token')
|
@@ -893,17 +883,26 @@ def send_get_request():
|
|
893 |
report = data.get('report', {})
|
894 |
messages = data.get('messages', {})
|
895 |
|
896 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
897 |
|
898 |
-
# Обновление или добавление каждого пользователя в базу данных
|
899 |
processed_emails = set()
|
900 |
for user_id, user_data in users_meta.items():
|
901 |
-
# Извлечение сообщений
|
902 |
-
user_messages = messages.get(user_id, [])
|
903 |
-
user_data['messages'] = user_messages
|
904 |
-
|
905 |
email = user_data.get('email')
|
906 |
-
if email
|
907 |
update_or_insert_user(DATABASE_NAME, user_data, mapping_template)
|
908 |
processed_emails.add(email)
|
909 |
|
@@ -914,6 +913,22 @@ def send_get_request():
|
|
914 |
|
915 |
|
916 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
917 |
|
918 |
|
919 |
|
|
|
809 |
# Обновление значения web_st
|
810 |
cursor.execute("UPDATE contacts SET web_st = ? WHERE email = ?", (web_st_value, email))
|
811 |
conn.commit()
|
|
|
812 |
logging.debug(f"User {email} web_st updated to {web_st_value}")
|
813 |
else:
|
|
|
814 |
logging.debug(f"User {email} not found, proceeding with insert")
|
815 |
|
|
|
|
|
|
|
|
|
816 |
# Преобразование данных пользователя на основе шаблона сопоставления
|
817 |
transformed_data = {}
|
818 |
for json_key, db_column in mapping_template.items():
|
|
|
846 |
# Добавление значения web_st в данные для вставки
|
847 |
transformed_data['web_st'] = web_st_value
|
848 |
|
|
|
|
|
|
|
849 |
# Обновление данных пользователя в базе данных
|
850 |
if user:
|
851 |
update_query = "UPDATE contacts SET "
|
|
|
869 |
conn.commit()
|
870 |
conn.close()
|
871 |
logging.debug(f"User with email {email} processed successfully")
|
|
|
872 |
@app.route('/send_get_request', methods=['GET'])
|
873 |
def send_get_request():
|
874 |
token = request.args.get('token')
|
|
|
883 |
report = data.get('report', {})
|
884 |
messages = data.get('messages', {})
|
885 |
|
886 |
+
report_json_str = report.get('report', '{}')
|
887 |
+
try:
|
888 |
+
report_json = json.loads(report_json_str)
|
889 |
+
except json.JSONDecodeError:
|
890 |
+
report_json = {}
|
891 |
+
|
892 |
+
messages_json_str = report.get('messages', '{}')
|
893 |
+
try:
|
894 |
+
messages_json = json.loads(messages_json_str)
|
895 |
+
except json.JSONDecodeError:
|
896 |
+
messages_json = {}
|
897 |
+
|
898 |
+
users_meta = report_json.get('usersMeta', {})
|
899 |
|
900 |
+
# Обновление или добавление каждого пользователя в базу данных data_gc.db
|
901 |
processed_emails = set()
|
902 |
for user_id, user_data in users_meta.items():
|
903 |
+
user_data['messages'] = messages_json.get(user_id, []) # Извлечение сообщений конкретного пользователя
|
|
|
|
|
|
|
904 |
email = user_data.get('email')
|
905 |
+
if email not in processed_emails:
|
906 |
update_or_insert_user(DATABASE_NAME, user_data, mapping_template)
|
907 |
processed_emails.add(email)
|
908 |
|
|
|
913 |
|
914 |
|
915 |
|
916 |
+
|
917 |
+
|
918 |
+
|
919 |
+
|
920 |
+
|
921 |
+
|
922 |
+
|
923 |
+
|
924 |
+
|
925 |
+
|
926 |
+
|
927 |
+
|
928 |
+
|
929 |
+
|
930 |
+
|
931 |
+
|
932 |
|
933 |
|
934 |
|