DmitrMakeev
commited on
Commit
•
c1ab869
1
Parent(s):
cd24c40
Update app.py
Browse files
app.py
CHANGED
@@ -791,6 +791,7 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
791 |
email = user_data.get('email')
|
792 |
logging.debug(f"Processing user with email: {email}")
|
793 |
|
|
|
794 |
cursor.execute("SELECT web_st FROM contacts WHERE email = ?", (email,))
|
795 |
user = cursor.fetchone()
|
796 |
logging.debug(f"User found: {user}")
|
@@ -823,11 +824,12 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
823 |
transformed_data['phone'] = phone
|
824 |
logging.debug(f"Transformed data after phone processing: {transformed_data}")
|
825 |
|
826 |
-
#
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
|
|
831 |
columns = ', '.join(transformed_data.keys()) + ", web_st"
|
832 |
placeholders = ', '.join('?' for _ in transformed_data) + ", ?"
|
833 |
insert_query = f"INSERT INTO contacts ({columns}) VALUES ({placeholders})"
|
|
|
791 |
email = user_data.get('email')
|
792 |
logging.debug(f"Processing user with email: {email}")
|
793 |
|
794 |
+
# Проверяем, существует ли пользователь с заданным email
|
795 |
cursor.execute("SELECT web_st FROM contacts WHERE email = ?", (email,))
|
796 |
user = cursor.fetchone()
|
797 |
logging.debug(f"User found: {user}")
|
|
|
824 |
transformed_data['phone'] = phone
|
825 |
logging.debug(f"Transformed data after phone processing: {transformed_data}")
|
826 |
|
827 |
+
# Если пользователь существует, увеличиваем значение web_st на единицу
|
828 |
+
if user:
|
829 |
+
update_query = "UPDATE contacts SET web_st = web_st + 1 WHERE email = ?"
|
830 |
+
cursor.execute(update_query, (email,))
|
831 |
+
else:
|
832 |
+
# Если пользователь не существует, вставляем новую запись с web_st равным 1
|
833 |
columns = ', '.join(transformed_data.keys()) + ", web_st"
|
834 |
placeholders = ', '.join('?' for _ in transformed_data) + ", ?"
|
835 |
insert_query = f"INSERT INTO contacts ({columns}) VALUES ({placeholders})"
|