Update app.py
Browse files
app.py
CHANGED
|
@@ -1650,13 +1650,12 @@ def verify_phone_number(phone_number):
|
|
| 1650 |
|
| 1651 |
if response.status_code == 200:
|
| 1652 |
result = response.json()
|
| 1653 |
-
return result
|
| 1654 |
else:
|
| 1655 |
-
return
|
| 1656 |
else:
|
| 1657 |
-
return
|
| 1658 |
|
| 1659 |
-
# Flask route для добавления или обновления контакта с проверкой номера
|
| 1660 |
@app.route('/add_data_ver', methods=['GET'])
|
| 1661 |
def add_data_ver():
|
| 1662 |
try:
|
|
@@ -1668,35 +1667,22 @@ def add_data_ver():
|
|
| 1668 |
name = request.args.get('name')
|
| 1669 |
phone = request.args.get('phone')
|
| 1670 |
email = request.args.get('email')
|
| 1671 |
-
pr1 = request.args.get('pr1')
|
| 1672 |
-
pr2 = request.args.get('pr2')
|
| 1673 |
-
pr3 = request.args.get('pr3')
|
| 1674 |
-
pr4 = request.args.get('pr4')
|
| 1675 |
-
pr5 = request.args.get('pr5')
|
| 1676 |
canal = request.args.get('canal', '')
|
| 1677 |
|
| 1678 |
if not name or not phone or not email:
|
| 1679 |
return "Parameters 'name', 'phone', and 'email' are required.", 400
|
| 1680 |
|
| 1681 |
-
#
|
| 1682 |
if phone.startswith('+'):
|
| 1683 |
phone = phone[1:]
|
| 1684 |
|
| 1685 |
-
#
|
| 1686 |
-
|
| 1687 |
-
ws_status = verification_result.get('existsWhatsapp', False)
|
| 1688 |
-
|
| 1689 |
-
# Определение переменных, если они не передаются
|
| 1690 |
-
vk_id = request.args.get('vk_id', None)
|
| 1691 |
-
chat_id = request.args.get('chat_id', None)
|
| 1692 |
-
ws_stop = request.args.get('ws_stop', None)
|
| 1693 |
-
web_statys = request.args.get('web_statys', None)
|
| 1694 |
-
fin_progress = request.args.get('fin_progress', None)
|
| 1695 |
-
shop_statys_full = request.args.get('shop_statys_full', None)
|
| 1696 |
-
ad_url = request.args.get('ad_url', None)
|
| 1697 |
-
curator = request.args.get('curator', None)
|
| 1698 |
-
key_pr = request.args.get('key_pr', None)
|
| 1699 |
-
n_con = request.args.get('n_con', None)
|
| 1700 |
|
| 1701 |
# Получение текущего времени в московском часовом поясе
|
| 1702 |
utc_now = datetime.utcnow()
|
|
@@ -1709,71 +1695,40 @@ def add_data_ver():
|
|
| 1709 |
cursor.execute('SELECT * FROM contacts WHERE phone = ? OR email = ?', (phone, email))
|
| 1710 |
existing_contact = cursor.fetchone()
|
| 1711 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1712 |
if existing_contact:
|
| 1713 |
-
update_query =
|
| 1714 |
-
|
| 1715 |
-
|
| 1716 |
-
|
| 1717 |
-
|
| 1718 |
-
|
| 1719 |
-
|
| 1720 |
-
|
| 1721 |
-
|
| 1722 |
-
if pr1 is not None:
|
| 1723 |
-
update_query += ", pr1 = ?"
|
| 1724 |
-
params.append(pr1)
|
| 1725 |
-
if pr2 is not None:
|
| 1726 |
-
update_query += ", pr2 = ?"
|
| 1727 |
-
params.append(pr2)
|
| 1728 |
-
if pr3 is not None:
|
| 1729 |
-
update_query += ", pr3 = ?"
|
| 1730 |
-
params.append(pr3)
|
| 1731 |
-
if pr4 is not None:
|
| 1732 |
-
update_query += ", pr4 = ?"
|
| 1733 |
-
params.append(pr4)
|
| 1734 |
-
if pr5 is not None:
|
| 1735 |
-
update_query += ", pr5 = ?"
|
| 1736 |
-
params.append(pr5)
|
| 1737 |
-
|
| 1738 |
-
update_query += " WHERE phone = ? OR email = ?"
|
| 1739 |
-
params.extend([phone, email])
|
| 1740 |
-
|
| 1741 |
-
cursor.execute(update_query, params)
|
| 1742 |
else:
|
| 1743 |
-
|
| 1744 |
-
|
| 1745 |
-
|
| 1746 |
-
|
| 1747 |
-
|
| 1748 |
-
params = [name, phone, email, vk_id, chat_id, ws_status, ws_stop, web_statys, fin_progress,
|
| 1749 |
-
shop_statys_full, ad_url, curator, key_pr, n_con, canal, data_t]
|
| 1750 |
-
|
| 1751 |
-
if pr1 is not None:
|
| 1752 |
-
insert_columns += ", pr1"
|
| 1753 |
-
placeholders += ", ?"
|
| 1754 |
-
params.append(pr1)
|
| 1755 |
-
if pr2 is not None:
|
| 1756 |
-
insert_columns += ", pr2"
|
| 1757 |
-
placeholders += ", ?"
|
| 1758 |
-
params.append(pr2)
|
| 1759 |
-
if pr3 is not None:
|
| 1760 |
-
insert_columns += ", pr3"
|
| 1761 |
-
placeholders += ", ?"
|
| 1762 |
-
params.append(pr3)
|
| 1763 |
-
if pr4 is not None:
|
| 1764 |
-
insert_columns += ", pr4"
|
| 1765 |
-
placeholders += ", ?"
|
| 1766 |
-
params.append(pr4)
|
| 1767 |
-
if pr5 is not None:
|
| 1768 |
-
insert_columns += ", pr5"
|
| 1769 |
-
placeholders += ", ?"
|
| 1770 |
-
params.append(pr5)
|
| 1771 |
-
|
| 1772 |
-
insert_query = f'''
|
| 1773 |
-
INSERT INTO contacts ({insert_columns}) VALUES ({placeholders})
|
| 1774 |
-
'''
|
| 1775 |
-
|
| 1776 |
-
cursor.execute(insert_query, params)
|
| 1777 |
|
| 1778 |
conn.commit()
|
| 1779 |
conn.close()
|
|
@@ -1798,8 +1753,6 @@ def add_data_ver():
|
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
-
|
| 1802 |
-
|
| 1803 |
initialize_requests()
|
| 1804 |
|
| 1805 |
|
|
|
|
| 1650 |
|
| 1651 |
if response.status_code == 200:
|
| 1652 |
result = response.json()
|
| 1653 |
+
return result.get('existsWhatsapp', False)
|
| 1654 |
else:
|
| 1655 |
+
return False
|
| 1656 |
else:
|
| 1657 |
+
return False
|
| 1658 |
|
|
|
|
| 1659 |
@app.route('/add_data_ver', methods=['GET'])
|
| 1660 |
def add_data_ver():
|
| 1661 |
try:
|
|
|
|
| 1667 |
name = request.args.get('name')
|
| 1668 |
phone = request.args.get('phone')
|
| 1669 |
email = request.args.get('email')
|
| 1670 |
+
pr1 = request.args.get('pr1', '')
|
| 1671 |
+
pr2 = request.args.get('pr2', '')
|
| 1672 |
+
pr3 = request.args.get('pr3', '')
|
| 1673 |
+
pr4 = request.args.get('pr4', '')
|
| 1674 |
+
pr5 = request.args.get('pr5', '')
|
| 1675 |
canal = request.args.get('canal', '')
|
| 1676 |
|
| 1677 |
if not name or not phone or not email:
|
| 1678 |
return "Parameters 'name', 'phone', and 'email' are required.", 400
|
| 1679 |
|
| 1680 |
+
# Clean up phone number by removing any leading plus sign
|
| 1681 |
if phone.startswith('+'):
|
| 1682 |
phone = phone[1:]
|
| 1683 |
|
| 1684 |
+
# Выполнение верификации номера телефона и добавление в ws_st
|
| 1685 |
+
ws_statys = verify_phone_number(phone)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1686 |
|
| 1687 |
# Получение текущего времени в московском часовом поясе
|
| 1688 |
utc_now = datetime.utcnow()
|
|
|
|
| 1695 |
cursor.execute('SELECT * FROM contacts WHERE phone = ? OR email = ?', (phone, email))
|
| 1696 |
existing_contact = cursor.fetchone()
|
| 1697 |
|
| 1698 |
+
# Преобразование данных пользователя для вставки
|
| 1699 |
+
user_data = {
|
| 1700 |
+
"name": name,
|
| 1701 |
+
"phone": phone,
|
| 1702 |
+
"email": email,
|
| 1703 |
+
"ws_st": ws_statys,
|
| 1704 |
+
"pr1": pr1,
|
| 1705 |
+
"pr2": pr2,
|
| 1706 |
+
"pr3": pr3,
|
| 1707 |
+
"pr4": pr4,
|
| 1708 |
+
"pr5": pr5,
|
| 1709 |
+
"canal": canal,
|
| 1710 |
+
"data_t": data_t
|
| 1711 |
+
}
|
| 1712 |
+
|
| 1713 |
+
# Обработка полей, которые могут быть NULL
|
| 1714 |
+
for field in ["vk_id", "chat_id", "ws_stop", "web_st", "fin_prog", "shop_st", "ad_url", "curator", "key_pr", "n_con"]:
|
| 1715 |
+
user_data[field] = ""
|
| 1716 |
+
|
| 1717 |
if existing_contact:
|
| 1718 |
+
update_query = "UPDATE contacts SET "
|
| 1719 |
+
update_values = []
|
| 1720 |
+
for column, value in user_data.items():
|
| 1721 |
+
update_query += f"{column} = ?, "
|
| 1722 |
+
update_values.append(value)
|
| 1723 |
+
update_query = update_query.rstrip(", ") + " WHERE phone = ? OR email = ?"
|
| 1724 |
+
update_values.extend([phone, email])
|
| 1725 |
+
cursor.execute(update_query, update_values)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1726 |
else:
|
| 1727 |
+
columns = ', '.join(user_data.keys())
|
| 1728 |
+
placeholders = ', '.join('?' for _ in user_data)
|
| 1729 |
+
insert_query = f"INSERT INTO contacts ({columns}) VALUES ({placeholders})"
|
| 1730 |
+
insert_values = list(user_data.values())
|
| 1731 |
+
cursor.execute(insert_query, insert_values)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1732 |
|
| 1733 |
conn.commit()
|
| 1734 |
conn.close()
|
|
|
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
|
|
|
|
|
|
| 1756 |
initialize_requests()
|
| 1757 |
|
| 1758 |
|