Update app.py
Browse files
app.py
CHANGED
@@ -1573,7 +1573,7 @@ def verify_phone_number(phone_number):
|
|
1573 |
response_body = response.json()
|
1574 |
return response_body.get('existsWhatsapp', 'false')
|
1575 |
else:
|
1576 |
-
return "
|
1577 |
|
1578 |
def parse_csv_data(data):
|
1579 |
parsed_data = []
|
@@ -1586,55 +1586,53 @@ def parse_csv_data(data):
|
|
1586 |
|
1587 |
def insert_data(data, verify_phone, add_curator):
|
1588 |
global current_curator_index
|
1589 |
-
|
1590 |
-
|
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 |
-
|
1599 |
-
|
|
|
|
|
|
|
1600 |
|
1601 |
-
|
1602 |
-
|
1603 |
-
continue
|
1604 |
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
1608 |
-
else:
|
1609 |
-
curator = row.get('curator', '')
|
1610 |
|
1611 |
-
|
1612 |
-
|
1613 |
-
|
1614 |
-
|
|
|
1615 |
|
1616 |
-
|
1617 |
-
|
|
|
|
|
1618 |
|
|
|
|
|
1619 |
|
1620 |
-
|
1621 |
-
|
1622 |
|
1623 |
-
|
1624 |
-
|
1625 |
-
|
1626 |
-
|
1627 |
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
1632 |
-
|
1633 |
-
|
1634 |
-
|
1635 |
|
1636 |
-
|
1637 |
-
conn.close()
|
1638 |
|
1639 |
@app.route('/upload_csv', methods=['POST'])
|
1640 |
def upload_csv():
|
@@ -1656,11 +1654,6 @@ def upload_csv():
|
|
1656 |
return jsonify({"message": "Data uploaded and inserted successfully"})
|
1657 |
return jsonify({"error": "Invalid file format"}), 400
|
1658 |
|
1659 |
-
|
1660 |
-
|
1661 |
-
|
1662 |
-
|
1663 |
-
|
1664 |
@app.route('/upl_csv', methods=['GET'])
|
1665 |
def se_upl_csv():
|
1666 |
api_sys_control = request.args.get('api_sys')
|
@@ -1686,8 +1679,6 @@ def se_upl_csv():
|
|
1686 |
|
1687 |
|
1688 |
|
1689 |
-
|
1690 |
-
|
1691 |
|
1692 |
|
1693 |
|
|
|
1573 |
response_body = response.json()
|
1574 |
return response_body.get('existsWhatsapp', 'false')
|
1575 |
else:
|
1576 |
+
return "false"
|
1577 |
|
1578 |
def parse_csv_data(data):
|
1579 |
parsed_data = []
|
|
|
1586 |
|
1587 |
def insert_data(data, verify_phone, add_curator):
|
1588 |
global current_curator_index
|
1589 |
+
with sqlite3.connect(DATABASE2) as conn:
|
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', 'gc_url', 'key_pr', 'n_con', 'canal', 'data_on', 'data_t', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gcpc']
|
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('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', '')]
|
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 |
|
1637 |
@app.route('/upload_csv', methods=['POST'])
|
1638 |
def upload_csv():
|
|
|
1654 |
return jsonify({"message": "Data uploaded and inserted successfully"})
|
1655 |
return jsonify({"error": "Invalid file format"}), 400
|
1656 |
|
|
|
|
|
|
|
|
|
|
|
1657 |
@app.route('/upl_csv', methods=['GET'])
|
1658 |
def se_upl_csv():
|
1659 |
api_sys_control = request.args.get('api_sys')
|
|
|
1679 |
|
1680 |
|
1681 |
|
|
|
|
|
1682 |
|
1683 |
|
1684 |
|