Update app.py
Browse files
app.py
CHANGED
|
@@ -1559,6 +1559,8 @@ def add_data_ver_cur():
|
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
|
|
|
|
|
|
| 1562 |
|
| 1563 |
DATABASE2 = 'data_gc.db'
|
| 1564 |
|
|
@@ -1573,10 +1575,6 @@ def verify_phone_number(phone_number):
|
|
| 1573 |
else:
|
| 1574 |
return "Error"
|
| 1575 |
|
| 1576 |
-
def clean_phone_number(phone):
|
| 1577 |
-
return ''.join(filter(str.isdigit, phone))
|
| 1578 |
-
|
| 1579 |
-
|
| 1580 |
def parse_csv_data(data):
|
| 1581 |
parsed_data = []
|
| 1582 |
for item in data:
|
|
@@ -1586,74 +1584,56 @@ def parse_csv_data(data):
|
|
| 1586 |
parsed_data.append(dict(zip(headers, row)))
|
| 1587 |
return parsed_data
|
| 1588 |
|
| 1589 |
-
|
| 1590 |
-
|
| 1591 |
-
|
| 1592 |
-
|
| 1593 |
-
|
| 1594 |
-
def clean_phone_number(phone):
|
| 1595 |
-
return ''.join(filter(str.isdigit, phone))
|
| 1596 |
-
|
| 1597 |
def insert_data(data, verify_phone, add_curator):
|
| 1598 |
global current_curator_index
|
| 1599 |
-
|
| 1600 |
-
|
| 1601 |
-
|
| 1602 |
-
for row in data:
|
| 1603 |
-
name = row.get('Name', '')
|
| 1604 |
-
phone = clean_phone_number(row.get('Phone', ''))
|
| 1605 |
-
email = row.get('Email', '')
|
| 1606 |
-
data_t = row.get('Date', '').strip('"')
|
| 1607 |
|
| 1608 |
-
|
| 1609 |
-
|
|
|
|
|
|
|
|
|
|
| 1610 |
|
| 1611 |
-
|
| 1612 |
-
|
| 1613 |
-
else:
|
| 1614 |
-
print(f"User with email {email} or phone {phone} does not exist. Inserting new data.")
|
| 1615 |
|
| 1616 |
-
|
| 1617 |
-
|
| 1618 |
-
|
| 1619 |
-
else:
|
| 1620 |
-
curator = row.get('curator', '')
|
| 1621 |
-
|
| 1622 |
-
if verify_phone == "1":
|
| 1623 |
-
verification_result = verify_phone_number(phone)
|
| 1624 |
-
print(f"Verification result for phone {phone}: {verification_result}") # Вывод результата верификации в консоль
|
| 1625 |
-
if verification_result == "True":
|
| 1626 |
-
ws_st = 1
|
| 1627 |
-
else:
|
| 1628 |
-
ws_st = 0
|
| 1629 |
-
else:
|
| 1630 |
-
ws_st = row.get('ws_st', '')
|
| 1631 |
|
| 1632 |
-
|
| 1633 |
-
|
|
|
|
|
|
|
|
|
|
| 1634 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1635 |
|
| 1636 |
-
|
| 1637 |
-
|
| 1638 |
|
| 1639 |
-
|
| 1640 |
-
|
| 1641 |
-
VALUES ({placeholders})
|
| 1642 |
-
'''
|
| 1643 |
|
| 1644 |
-
|
| 1645 |
-
|
| 1646 |
-
|
| 1647 |
-
|
| 1648 |
-
except Exception as e:
|
| 1649 |
-
print(f"Error inserting row: {row}")
|
| 1650 |
-
print(f"Error message: {str(e)}")
|
| 1651 |
-
conn.rollback()
|
| 1652 |
-
raise
|
| 1653 |
|
| 1654 |
-
|
| 1655 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1656 |
|
|
|
|
|
|
|
| 1657 |
|
| 1658 |
@app.route('/upload_csv', methods=['POST'])
|
| 1659 |
def upload_csv():
|
|
@@ -1699,6 +1679,13 @@ def se_upl_csv():
|
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
|
|
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
+
DATABASE2 = 'data_gc.db'
|
| 1563 |
+
|
| 1564 |
|
| 1565 |
DATABASE2 = 'data_gc.db'
|
| 1566 |
|
|
|
|
| 1575 |
else:
|
| 1576 |
return "Error"
|
| 1577 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1578 |
def parse_csv_data(data):
|
| 1579 |
parsed_data = []
|
| 1580 |
for item in data:
|
|
|
|
| 1584 |
parsed_data.append(dict(zip(headers, row)))
|
| 1585 |
return parsed_data
|
| 1586 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1587 |
def insert_data(data, verify_phone, add_curator):
|
| 1588 |
global current_curator_index
|
| 1589 |
+
conn = sqlite3.connect(DATABASE2)
|
| 1590 |
+
cursor = conn.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1591 |
|
| 1592 |
+
for row in data:
|
| 1593 |
+
name = row.get('Name', '')
|
| 1594 |
+
phone = row.get('Phone', '').lstrip('+')
|
| 1595 |
+
email = row.get('Email', '')
|
| 1596 |
+
data_t = row.get('Date', '').strip('"')
|
| 1597 |
|
| 1598 |
+
cursor.execute("SELECT 1 FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
| 1599 |
+
user_exists = cursor.fetchone()
|
|
|
|
|
|
|
| 1600 |
|
| 1601 |
+
if user_exists:
|
| 1602 |
+
print(f"User with email {email} or phone {phone} already exists. Skipping insert.")
|
| 1603 |
+
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1604 |
|
| 1605 |
+
if add_curator == "1":
|
| 1606 |
+
curator = curators[current_curator_index]
|
| 1607 |
+
current_curator_index = (current_curator_index + 1) % len(curators)
|
| 1608 |
+
else:
|
| 1609 |
+
curator = row.get('curator', '')
|
| 1610 |
|
| 1611 |
+
if verify_phone == "1":
|
| 1612 |
+
ws_st = verify_phone_number(phone)
|
| 1613 |
+
else:
|
| 1614 |
+
ws_st = row.get('ws_st', '')
|
| 1615 |
|
| 1616 |
+
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', 'ad_url', 'key_pr', 'n_con', 'canal', 'data_t', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']
|
| 1617 |
+
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('ad_url', ''), row.get('key_pr', ''), row.get('n_con', ''), row.get('canal', ''), data_t, row.get('utm_source', ''), row.get('utm_medium', ''), row.get('utm_campaign', ''), row.get('utm_term', ''), row.get('utm_content', '')]
|
| 1618 |
|
| 1619 |
+
placeholders = ', '.join(['?' for _ in columns])
|
| 1620 |
+
columns_str = ', '.join(columns)
|
|
|
|
|
|
|
| 1621 |
|
| 1622 |
+
query = f'''
|
| 1623 |
+
INSERT INTO contacts ({columns_str})
|
| 1624 |
+
VALUES ({placeholders})
|
| 1625 |
+
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1626 |
|
| 1627 |
+
try:
|
| 1628 |
+
cursor.execute(query, values)
|
| 1629 |
+
except Exception as e:
|
| 1630 |
+
print(f"Error inserting row: {row}")
|
| 1631 |
+
print(f"Error message: {str(e)}")
|
| 1632 |
+
conn.rollback()
|
| 1633 |
+
raise
|
| 1634 |
|
| 1635 |
+
conn.commit()
|
| 1636 |
+
conn.close()
|
| 1637 |
|
| 1638 |
@app.route('/upload_csv', methods=['POST'])
|
| 1639 |
def upload_csv():
|
|
|
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
+
|
| 1683 |
+
|
| 1684 |
+
|
| 1685 |
+
|
| 1686 |
+
|
| 1687 |
+
|
| 1688 |
+
|
| 1689 |
|
| 1690 |
|
| 1691 |
|