DmitrMakeev
commited on
Commit
•
002d6b1
1
Parent(s):
259ebdf
Update app.py
Browse files
app.py
CHANGED
@@ -776,10 +776,17 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
776 |
cursor = conn.cursor()
|
777 |
|
778 |
email = user_data.get('email')
|
|
|
779 |
cursor.execute("SELECT web_st FROM contacts WHERE email = ?", (email,))
|
780 |
user = cursor.fetchone()
|
781 |
|
782 |
-
transformed_data = {
|
|
|
|
|
|
|
|
|
|
|
|
|
783 |
|
784 |
required_fields = [
|
785 |
"vk_id", "chat_id", "ws_st", "ws_stop", "web_st", "fin_prog",
|
@@ -841,9 +848,10 @@ def send_get_request():
|
|
841 |
|
842 |
users_meta = report_json.get('usersMeta', {})
|
843 |
|
|
|
844 |
for user_id, user_data in users_meta.items():
|
845 |
user_data['messages'] = messages_json
|
846 |
-
update_or_insert_user(DATABASE_NAME, user_data,
|
847 |
|
848 |
return jsonify({'status': 'User data saved successfully'})
|
849 |
else:
|
|
|
776 |
cursor = conn.cursor()
|
777 |
|
778 |
email = user_data.get('email')
|
779 |
+
|
780 |
cursor.execute("SELECT web_st FROM contacts WHERE email = ?", (email,))
|
781 |
user = cursor.fetchone()
|
782 |
|
783 |
+
transformed_data = {}
|
784 |
+
for json_key, db_column in mapping_template.items():
|
785 |
+
value = user_data.get(json_key, "")
|
786 |
+
if isinstance(value, list):
|
787 |
+
transformed_data[db_column] = "-1" if value else "0"
|
788 |
+
else:
|
789 |
+
transformed_data[db_column] = str(value)
|
790 |
|
791 |
required_fields = [
|
792 |
"vk_id", "chat_id", "ws_st", "ws_stop", "web_st", "fin_prog",
|
|
|
848 |
|
849 |
users_meta = report_json.get('usersMeta', {})
|
850 |
|
851 |
+
# Обновление или добавление каждого пользователя в базу данных data_gc.db
|
852 |
for user_id, user_data in users_meta.items():
|
853 |
user_data['messages'] = messages_json
|
854 |
+
update_or_insert_user(DATABASE_NAME, user_data, template)
|
855 |
|
856 |
return jsonify({'status': 'User data saved successfully'})
|
857 |
else:
|