DmitrMakeev
commited on
Commit
•
ff2bffe
1
Parent(s):
9d046ba
Update app.py
Browse files
app.py
CHANGED
@@ -799,6 +799,27 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
799 |
user = cursor.fetchone()
|
800 |
logging.debug(f"User found: {user}")
|
801 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
802 |
# Преобразование данных пользователя на основе шаблона сопоставления
|
803 |
transformed_data = {}
|
804 |
for json_key, db_column in mapping_template.items():
|
@@ -829,13 +850,8 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
829 |
transformed_data['phone'] = phone
|
830 |
logging.debug(f"Transformed data after phone processing: {transformed_data}")
|
831 |
|
832 |
-
#
|
833 |
-
|
834 |
-
if user:
|
835 |
-
# Проверка текущего значения web_st и его инкрементация
|
836 |
-
current_web_st = user[0] if user[0] is not None and user[0] != "" else 0
|
837 |
-
web_st_value = int(current_web_st) + 1
|
838 |
-
logging.debug(f"Calculated web_st_value: {web_st_value}")
|
839 |
|
840 |
# Обновление данных пользователя в базе данных
|
841 |
if user:
|
@@ -844,15 +860,15 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
844 |
for column, value in transformed_data.items():
|
845 |
update_query += f"{column} = ?, "
|
846 |
update_values.append(value)
|
847 |
-
update_query
|
848 |
-
update_values.
|
849 |
logging.debug(f"Update query: {update_query} with values: {update_values}")
|
850 |
cursor.execute(update_query, update_values)
|
851 |
else:
|
852 |
-
columns = ', '.join(transformed_data.keys())
|
853 |
-
placeholders = ', '.join('?' for _ in transformed_data)
|
854 |
insert_query = f"INSERT INTO contacts ({columns}) VALUES ({placeholders})"
|
855 |
-
insert_values = list(transformed_data.values())
|
856 |
logging.debug(f"Insert query: {insert_query} with values: {insert_values}")
|
857 |
cursor.execute(insert_query, insert_values)
|
858 |
|
@@ -920,7 +936,6 @@ def send_get_request():
|
|
920 |
|
921 |
|
922 |
|
923 |
-
|
924 |
|
925 |
|
926 |
@app.route('/biz_v', methods=['GET'])
|
|
|
799 |
user = cursor.fetchone()
|
800 |
logging.debug(f"User found: {user}")
|
801 |
|
802 |
+
# Вынесение увеличения значения web_st в отдельный блок
|
803 |
+
web_st_value = 3 # Инициализация значения web_st
|
804 |
+
if user:
|
805 |
+
# Проверка текущего значения web_st и его инкрементация
|
806 |
+
current_web_st = user[0] if user[0] is not None and user[0] != "" else 0
|
807 |
+
web_st_value = int(current_web_st) + 1
|
808 |
+
logging.debug(f"Calculated web_st_value: {web_st_value}")
|
809 |
+
|
810 |
+
# Обновление значения web_st
|
811 |
+
cursor.execute("UPDATE contacts SET web_st = ? WHERE email = ?", (web_st_value, email))
|
812 |
+
conn.commit()
|
813 |
+
conn.close()
|
814 |
+
logging.debug(f"User {email} web_st updated to {web_st_value}")
|
815 |
+
else:
|
816 |
+
conn.close()
|
817 |
+
logging.debug(f"User {email} not found, proceeding with insert")
|
818 |
+
|
819 |
+
# Открываем соединение снова для остальных операций
|
820 |
+
conn = sqlite3.connect(db_name)
|
821 |
+
cursor = conn.cursor()
|
822 |
+
|
823 |
# Преобразование данных пользователя на основе шаблона сопоставления
|
824 |
transformed_data = {}
|
825 |
for json_key, db_column in mapping_template.items():
|
|
|
850 |
transformed_data['phone'] = phone
|
851 |
logging.debug(f"Transformed data after phone processing: {transformed_data}")
|
852 |
|
853 |
+
# Добавление значения web_st в данные для вставки
|
854 |
+
transformed_data['web_st'] = web_st_value
|
|
|
|
|
|
|
|
|
|
|
855 |
|
856 |
# Обновление данных пользователя в базе данных
|
857 |
if user:
|
|
|
860 |
for column, value in transformed_data.items():
|
861 |
update_query += f"{column} = ?, "
|
862 |
update_values.append(value)
|
863 |
+
update_query = update_query.rstrip(", ") + " WHERE email = ?"
|
864 |
+
update_values.append(email)
|
865 |
logging.debug(f"Update query: {update_query} with values: {update_values}")
|
866 |
cursor.execute(update_query, update_values)
|
867 |
else:
|
868 |
+
columns = ', '.join(transformed_data.keys())
|
869 |
+
placeholders = ', '.join('?' for _ in transformed_data)
|
870 |
insert_query = f"INSERT INTO contacts ({columns}) VALUES ({placeholders})"
|
871 |
+
insert_values = list(transformed_data.values())
|
872 |
logging.debug(f"Insert query: {insert_query} with values: {insert_values}")
|
873 |
cursor.execute(insert_query, insert_values)
|
874 |
|
|
|
936 |
|
937 |
|
938 |
|
|
|
939 |
|
940 |
|
941 |
@app.route('/biz_v', methods=['GET'])
|