Update app.py
Browse files
app.py
CHANGED
@@ -1573,15 +1573,6 @@ def verify_phone_number(phone_number):
|
|
1573 |
else:
|
1574 |
return "Error"
|
1575 |
|
1576 |
-
def parse_csv_data(data):
|
1577 |
-
parsed_data = []
|
1578 |
-
for item in data:
|
1579 |
-
for key, value in item.items():
|
1580 |
-
headers = key.split(';')
|
1581 |
-
row = value.split(';')
|
1582 |
-
parsed_data.append(dict(zip(headers, row)))
|
1583 |
-
return parsed_data
|
1584 |
-
|
1585 |
def insert_data(data, verify_phone, add_curator):
|
1586 |
global current_curator_index
|
1587 |
conn = sqlite3.connect(DATABASE2)
|
@@ -1597,8 +1588,9 @@ def insert_data(data, verify_phone, add_curator):
|
|
1597 |
user_exists = cursor.fetchone()
|
1598 |
|
1599 |
if user_exists:
|
1600 |
-
print(f"User with email {email} or phone {phone} already exists.
|
1601 |
-
|
|
|
1602 |
|
1603 |
if add_curator == "1":
|
1604 |
curator = curators[current_curator_index]
|
@@ -1606,9 +1598,6 @@ def insert_data(data, verify_phone, add_curator):
|
|
1606 |
else:
|
1607 |
curator = row.get('curator', '')
|
1608 |
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
if verify_phone == "1":
|
1613 |
ws_st = verify_phone_number(phone)
|
1614 |
if ws_st == "true":
|
@@ -1618,29 +1607,18 @@ def insert_data(data, verify_phone, add_curator):
|
|
1618 |
else:
|
1619 |
ws_st = row.get('ws_st', '')
|
1620 |
|
1621 |
-
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
1625 |
-
|
1626 |
columns = ['name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog', 'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator', 'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'gc_url', 'key_pr', 'n_con', 'canal', 'data_on', 'data_t', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gcpc']
|
1627 |
-
values = [name, phone, email, row.get('vk_id', ''), row.get('chat_id', ''),
|
1628 |
|
1629 |
placeholders = ', '.join(['?' for _ in columns])
|
1630 |
columns_str = ', '.join(columns)
|
1631 |
|
1632 |
-
|
1633 |
-
|
1634 |
-
|
1635 |
-
|
1636 |
-
|
1637 |
-
|
1638 |
-
cursor.execute(query, values)
|
1639 |
-
except Exception as e:
|
1640 |
-
print(f"Error inserting row: {row}")
|
1641 |
-
print(f"Error message: {str(e)}")
|
1642 |
-
conn.rollback()
|
1643 |
-
raise
|
1644 |
|
1645 |
conn.commit()
|
1646 |
conn.close()
|
|
|
1573 |
else:
|
1574 |
return "Error"
|
1575 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1576 |
def insert_data(data, verify_phone, add_curator):
|
1577 |
global current_curator_index
|
1578 |
conn = sqlite3.connect(DATABASE2)
|
|
|
1588 |
user_exists = cursor.fetchone()
|
1589 |
|
1590 |
if user_exists:
|
1591 |
+
print(f"User with email {email} or phone {phone} already exists. Updating data.")
|
1592 |
+
else:
|
1593 |
+
print(f"User with email {email} or phone {phone} does not exist. Inserting new data.")
|
1594 |
|
1595 |
if add_curator == "1":
|
1596 |
curator = curators[current_curator_index]
|
|
|
1598 |
else:
|
1599 |
curator = row.get('curator', '')
|
1600 |
|
|
|
|
|
|
|
1601 |
if verify_phone == "1":
|
1602 |
ws_st = verify_phone_number(phone)
|
1603 |
if ws_st == "true":
|
|
|
1607 |
else:
|
1608 |
ws_st = row.get('ws_st', '')
|
1609 |
|
|
|
|
|
|
|
|
|
|
|
1610 |
columns = ['name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog', 'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator', 'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'gc_url', 'key_pr', 'n_con', 'canal', 'data_on', 'data_t', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gcpc']
|
1611 |
+
values = [name, phone, email, row.get('vk_id', ''), row.get('chat_id', ''), ws_st, row.get('ws_stop', ''), row.get('web_st', 0), row.get('fin_prog', 0), row.get('b_city', ''), row.get('b_fin', ''), row.get('b_ban', ''), row.get('b_ign', ''), row.get('b_baners', ''), row.get('b_butt', ''), row.get('b_mess', ''), row.get('shop_st', ''), curator, row.get('pr1', ''), row.get('pr2', ''), row.get('pr3', ''), row.get('pr4', ''), row.get('pr5', ''), row.get('gc_url', ''), row.get('key_pr', ''), row.get('n_con', ''), row.get('canal', ''), row.get('data_on', ''), row.get('data_t', ''), row.get('utm_source', ''), row.get('utm_medium', ''), row.get('utm_campaign', ''), row.get('utm_term', ''), row.get('utm_content', ''), row.get('gcpc', '')]
|
1612 |
|
1613 |
placeholders = ', '.join(['?' for _ in columns])
|
1614 |
columns_str = ', '.join(columns)
|
1615 |
|
1616 |
+
if user_exists:
|
1617 |
+
update_query = f"UPDATE contacts SET {', '.join([f'{col} = ?' for col in columns])} WHERE email = ? OR phone = ?"
|
1618 |
+
cursor.execute(update_query, values + [email, phone])
|
1619 |
+
else:
|
1620 |
+
insert_query = f"INSERT INTO contacts ({columns_str}) VALUES ({placeholders})"
|
1621 |
+
cursor.execute(insert_query, values)
|
|
|
|
|
|
|
|
|
|
|
|
|
1622 |
|
1623 |
conn.commit()
|
1624 |
conn.close()
|