DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -785,7 +785,7 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
785 |
for json_key, db_column in mapping_template.items():
|
786 |
value = user_data.get(json_key, "")
|
787 |
if isinstance(value, list):
|
788 |
-
transformed_data[db_column] = "1" if value else "0"
|
789 |
else:
|
790 |
transformed_data[db_column] = str(value)
|
791 |
|
@@ -801,7 +801,7 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
801 |
transformed_data[field] = ""
|
802 |
|
803 |
if user:
|
804 |
-
|
805 |
|
806 |
update_query = "UPDATE contacts SET "
|
807 |
update_values = []
|
@@ -809,7 +809,7 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
809 |
update_query += f"{column} = ?, "
|
810 |
update_values.append(value)
|
811 |
update_query += "web_st = ? WHERE email = ?"
|
812 |
-
update_values.extend([
|
813 |
cursor.execute(update_query, update_values)
|
814 |
else:
|
815 |
columns = ', '.join(transformed_data.keys()) + ", web_st"
|
@@ -833,43 +833,6 @@ def send_get_request():
|
|
833 |
data = response.json()
|
834 |
|
835 |
report = data.get('report', {})
|
836 |
-
|
837 |
-
# Извлечение полей из отчета
|
838 |
-
|
839 |
-
report_json_str = report.get('report', '{}')
|
840 |
-
|
841 |
-
# Обработка строкового JSON в report
|
842 |
-
try:
|
843 |
-
report_json = json.loads(report_json_str)
|
844 |
-
except json.JSONDecodeError:
|
845 |
-
report_json = {}
|
846 |
-
# Извлечение данных отчета
|
847 |
-
messages = data.get('messages', {})
|
848 |
-
|
849 |
-
# Извлечение полей из отчета
|
850 |
-
|
851 |
-
messages_json_str = report.get('messages', '{}')
|
852 |
-
|
853 |
-
# Обработка строкового JSON в report
|
854 |
-
try:
|
855 |
-
messages_json = json.loads(messages_json_str)
|
856 |
-
except json.JSONDecodeError:
|
857 |
-
messages_json = {}
|
858 |
-
# Возврат результата
|
859 |
-
result = {
|
860 |
-
|
861 |
-
'report': report_json,
|
862 |
-
'messages': messages_json
|
863 |
-
|
864 |
-
}
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
report = result
|
873 |
messages = data.get('messages', {})
|
874 |
|
875 |
report_json_str = report.get('report', '{}')
|
|
|
785 |
for json_key, db_column in mapping_template.items():
|
786 |
value = user_data.get(json_key, "")
|
787 |
if isinstance(value, list):
|
788 |
+
transformed_data[db_column] = "-1" if value else "0"
|
789 |
else:
|
790 |
transformed_data[db_column] = str(value)
|
791 |
|
|
|
801 |
transformed_data[field] = ""
|
802 |
|
803 |
if user:
|
804 |
+
web_st_value = int(user[0]) + 1
|
805 |
|
806 |
update_query = "UPDATE contacts SET "
|
807 |
update_values = []
|
|
|
809 |
update_query += f"{column} = ?, "
|
810 |
update_values.append(value)
|
811 |
update_query += "web_st = ? WHERE email = ?"
|
812 |
+
update_values.extend([web_st_value, email])
|
813 |
cursor.execute(update_query, update_values)
|
814 |
else:
|
815 |
columns = ', '.join(transformed_data.keys()) + ", web_st"
|
|
|
833 |
data = response.json()
|
834 |
|
835 |
report = data.get('report', {})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
836 |
messages = data.get('messages', {})
|
837 |
|
838 |
report_json_str = report.get('report', '{}')
|