Update app.py
Browse files
app.py
CHANGED
|
@@ -1611,8 +1611,8 @@ def verify_phone_number(phone_number):
|
|
| 1611 |
response_body = response.json()
|
| 1612 |
return response_body.get('existsWhatsapp', 'false')
|
| 1613 |
else:
|
| 1614 |
-
return "
|
| 1615 |
-
|
| 1616 |
def parse_csv_data(data):
|
| 1617 |
parsed_data = []
|
| 1618 |
for item in data:
|
|
@@ -1622,66 +1622,55 @@ def parse_csv_data(data):
|
|
| 1622 |
parsed_data.append(dict(zip(headers, row)))
|
| 1623 |
return parsed_data
|
| 1624 |
|
| 1625 |
-
def clean_phone_number(phone_number):
|
| 1626 |
-
# Удаляем все символы, кроме цифр
|
| 1627 |
-
return re.sub(r'\D', '', phone_number)
|
| 1628 |
-
|
| 1629 |
def insert_data(data, verify_phone, add_curator):
|
| 1630 |
global current_curator_index
|
| 1631 |
-
|
| 1632 |
-
|
| 1633 |
-
|
| 1634 |
-
for row in data:
|
| 1635 |
-
name = row.get('Name', '')
|
| 1636 |
-
phone = row.get('Phone', '').lstrip('+')
|
| 1637 |
-
email = row.get('Email', '')
|
| 1638 |
-
data_t = row.get('Date', '').lstrip('"')
|
| 1639 |
|
| 1640 |
-
|
| 1641 |
-
|
|
|
|
|
|
|
|
|
|
| 1642 |
|
| 1643 |
-
|
| 1644 |
-
|
| 1645 |
|
| 1646 |
-
|
| 1647 |
-
|
| 1648 |
-
|
| 1649 |
|
| 1650 |
-
|
| 1651 |
-
|
| 1652 |
-
|
| 1653 |
-
|
| 1654 |
-
|
| 1655 |
|
| 1656 |
-
|
| 1657 |
-
|
| 1658 |
-
|
| 1659 |
-
|
| 1660 |
|
| 1661 |
-
|
| 1662 |
-
|
| 1663 |
|
| 1664 |
-
|
| 1665 |
-
|
| 1666 |
|
| 1667 |
-
|
| 1668 |
-
|
| 1669 |
-
|
| 1670 |
-
|
| 1671 |
|
| 1672 |
-
|
| 1673 |
-
|
| 1674 |
-
|
| 1675 |
-
|
| 1676 |
-
|
| 1677 |
-
|
| 1678 |
-
|
| 1679 |
-
print(f"Error message: {str(e)}")
|
| 1680 |
-
conn.rollback()
|
| 1681 |
-
raise
|
| 1682 |
|
| 1683 |
-
|
| 1684 |
-
conn.close()
|
| 1685 |
|
| 1686 |
@app.route('/upload_csv', methods=['POST'])
|
| 1687 |
def upload_csv():
|
|
@@ -1717,6 +1706,7 @@ def se_upl_csv():
|
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
|
|
|
| 1720 |
DATABASE = 'data_gc.db'
|
| 1721 |
|
| 1722 |
# Функция для очистки номера телефона
|
|
|
|
| 1611 |
response_body = response.json()
|
| 1612 |
return response_body.get('existsWhatsapp', 'false')
|
| 1613 |
else:
|
| 1614 |
+
return "false"
|
| 1615 |
+
|
| 1616 |
def parse_csv_data(data):
|
| 1617 |
parsed_data = []
|
| 1618 |
for item in data:
|
|
|
|
| 1622 |
parsed_data.append(dict(zip(headers, row)))
|
| 1623 |
return parsed_data
|
| 1624 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1625 |
def insert_data(data, verify_phone, add_curator):
|
| 1626 |
global current_curator_index
|
| 1627 |
+
with sqlite3.connect(DATABASE2) as conn:
|
| 1628 |
+
cursor = conn.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1629 |
|
| 1630 |
+
for row in data:
|
| 1631 |
+
name = row.get('Name', '')
|
| 1632 |
+
phone = row.get('Phone', '').lstrip('+')
|
| 1633 |
+
email = row.get('Email', '')
|
| 1634 |
+
data_t = row.get('Date', '').strip('"')
|
| 1635 |
|
| 1636 |
+
cursor.execute("SELECT 1 FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
| 1637 |
+
user_exists = cursor.fetchone()
|
| 1638 |
|
| 1639 |
+
if user_exists:
|
| 1640 |
+
print(f"User with email {email} or phone {phone} already exists. Skipping insert.")
|
| 1641 |
+
continue
|
| 1642 |
|
| 1643 |
+
if add_curator == "1":
|
| 1644 |
+
curator = curators[current_curator_index]
|
| 1645 |
+
current_curator_index = (current_curator_index + 1) % len(curators)
|
| 1646 |
+
else:
|
| 1647 |
+
curator = row.get('curator', '')
|
| 1648 |
|
| 1649 |
+
if verify_phone == "1":
|
| 1650 |
+
ws_st = verify_phone_number(phone)
|
| 1651 |
+
else:
|
| 1652 |
+
ws_st = row.get('ws_st', '')
|
| 1653 |
|
| 1654 |
+
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']
|
| 1655 |
+
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', '')]
|
| 1656 |
|
| 1657 |
+
placeholders = ', '.join(['?' for _ in columns])
|
| 1658 |
+
columns_str = ', '.join(columns)
|
| 1659 |
|
| 1660 |
+
query = f'''
|
| 1661 |
+
INSERT INTO contacts ({columns_str})
|
| 1662 |
+
VALUES ({placeholders})
|
| 1663 |
+
'''
|
| 1664 |
|
| 1665 |
+
try:
|
| 1666 |
+
cursor.execute(query, values)
|
| 1667 |
+
except Exception as e:
|
| 1668 |
+
print(f"Error inserting row: {row}")
|
| 1669 |
+
print(f"Error message: {str(e)}")
|
| 1670 |
+
conn.rollback()
|
| 1671 |
+
raise
|
|
|
|
|
|
|
|
|
|
| 1672 |
|
| 1673 |
+
conn.commit()
|
|
|
|
| 1674 |
|
| 1675 |
@app.route('/upload_csv', methods=['POST'])
|
| 1676 |
def upload_csv():
|
|
|
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
+
|
| 1710 |
DATABASE = 'data_gc.db'
|
| 1711 |
|
| 1712 |
# Функция для очистки номера телефона
|