DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1628,54 +1628,6 @@ def gc_forms():
|
|
1628 |
|
1629 |
DATABASE_NAME3 = 'data_gc.db'
|
1630 |
|
1631 |
-
def verify_phone_number(phone_number):
|
1632 |
-
verifikation_start = "1"
|
1633 |
-
print(f"verifikation_start: {verifikation_start}")
|
1634 |
-
|
1635 |
-
if verifikation_start == "1":
|
1636 |
-
# Переменные окружения для сборки URL
|
1637 |
-
wa_url = "https://api.green-api.com/waInstance"
|
1638 |
-
wa_ak = "1101952913"
|
1639 |
-
ws_url_ver = "/checkWhatsapp/"
|
1640 |
-
wa_api_key = "fb4986a9d9cb40ef9be6c7b08cb9c98b7a3b1dc8c6834b0b92"
|
1641 |
-
|
1642 |
-
full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
|
1643 |
-
print(f"Full URL: {full_url_ver}")
|
1644 |
-
|
1645 |
-
# Создаем payload для запроса
|
1646 |
-
payload = json.dumps({
|
1647 |
-
"phoneNumber": phone_number
|
1648 |
-
})
|
1649 |
-
headers = {
|
1650 |
-
'Content-Type': 'application/json'
|
1651 |
-
}
|
1652 |
-
|
1653 |
-
# Отправляем POST-запрос
|
1654 |
-
response = requests.post(full_url_ver, headers=headers, data=payload)
|
1655 |
-
|
1656 |
-
# Печатаем статус ответа
|
1657 |
-
print(f"Response Status Code: {response.status_code}")
|
1658 |
-
|
1659 |
-
# Проверяем статус код ответа
|
1660 |
-
if response.status_code == 200:
|
1661 |
-
# Печатаем текст ответа от сервера
|
1662 |
-
response_body = response.json()
|
1663 |
-
print(f"Response Body: {response_body}")
|
1664 |
-
|
1665 |
-
# Извлекаем значение из JSON
|
1666 |
-
exists_whatsapp = response_body.get('existsWhatsapp', 'false')
|
1667 |
-
print(f"existsWhatsapp: {exists_whatsapp}")
|
1668 |
-
|
1669 |
-
# Возвращаем значение
|
1670 |
-
return exists_whatsapp
|
1671 |
-
else:
|
1672 |
-
print("Error: Unable to fetch data")
|
1673 |
-
return "Error"
|
1674 |
-
else:
|
1675 |
-
print("Verification not started")
|
1676 |
-
return "Verification not started"
|
1677 |
-
|
1678 |
-
# Функция для добавления или обновления контакта в базе данных
|
1679 |
def add_or_update_contact(contact_data):
|
1680 |
conn = sqlite3.connect(DATABASE_NAME3)
|
1681 |
cursor = conn.cursor()
|
@@ -1685,10 +1637,15 @@ def add_or_update_contact(contact_data):
|
|
1685 |
logging.error(f"Missing email in contact data: {contact_data}")
|
1686 |
return
|
1687 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1688 |
cursor.execute("SELECT id FROM contacts WHERE email = ?", (email,))
|
1689 |
contact = cursor.fetchone()
|
1690 |
|
1691 |
-
# List all fields for updating or inserting
|
1692 |
fields = [
|
1693 |
'name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog',
|
1694 |
'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator',
|
@@ -1699,52 +1656,50 @@ def add_or_update_contact(contact_data):
|
|
1699 |
|
1700 |
if contact:
|
1701 |
update_query = f"UPDATE contacts SET {placeholders} WHERE id = ?"
|
1702 |
-
cursor.execute(update_query, (*[contact_data.get(field, '
|
1703 |
else:
|
1704 |
insert_query = f"INSERT INTO contacts ({', '.join(fields)}) VALUES ({', '.join(['?' for _ in fields])})"
|
1705 |
-
cursor.execute(insert_query, tuple(contact_data.get(field, '
|
1706 |
|
1707 |
conn.commit()
|
1708 |
conn.close()
|
1709 |
|
1710 |
@app.route('/add_data_ver', methods=['GET'])
|
1711 |
def add_data_ver():
|
1712 |
-
# Извлечение параметров запроса с дефолтными значениями нижнего подчеркивания
|
1713 |
contact_data = {
|
1714 |
-
'name': request.args.get('name', '
|
1715 |
-
'phone': request.args.get('phone', '
|
1716 |
-
'email': request.args.get('email', '
|
1717 |
-
'vk_id': request.args.get('vk_id', '
|
1718 |
-
'chat_id': request.args.get('chat_id', '
|
1719 |
-
'ws_st': request.args.get('ws_st', '
|
1720 |
-
'ws_stop': request.args.get('ws_stop', '
|
1721 |
-
'web_st': request.args.get('web_st', '
|
1722 |
'fin_prog': request.args.get('fin_prog', '5'),
|
1723 |
-
'b_city': request.args.get('b_city', '
|
1724 |
-
'b_fin': request.args.get('b_fin', '
|
1725 |
-
'b_ban': request.args.get('b_ban', '
|
1726 |
-
'b_ign': request.args.get('b_ign', '
|
1727 |
-
'b_baners': request.args.get('b_baners', '
|
1728 |
-
'b_butt': request.args.get('b_butt', '
|
1729 |
-
'b_mess': request.args.get('b_mess', '
|
1730 |
-
'shop_st': request.args.get('shop_st', '
|
1731 |
-
'curator': request.args.get('curator', '
|
1732 |
-
'pr1': request.args.get('pr1', '
|
1733 |
-
'pr2': request.args.get('pr2', '
|
1734 |
-
'pr3': request.args.get('pr3', '
|
1735 |
-
'pr4': request.args.get('pr4', '
|
1736 |
-
'pr5': request.args.get('pr5', '
|
1737 |
-
'ad_url': request.args.get('ad_url', '
|
1738 |
-
'key_pr': request.args.get('key_pr', '
|
1739 |
-
'n_con': request.args.get('n_con', '
|
1740 |
-
'canal': request.args.get('canal', '
|
1741 |
-
'data_t':
|
1742 |
}
|
1743 |
|
1744 |
-
# Получение значения проверки номера телефона
|
1745 |
phone_verification_response = verify_phone_number(contact_data['phone'])
|
1746 |
if phone_verification_response is not None:
|
1747 |
-
contact_data['ws_st'] = phone_verification_response
|
1748 |
|
1749 |
try:
|
1750 |
add_or_update_contact(contact_data)
|
|
|
1628 |
|
1629 |
DATABASE_NAME3 = 'data_gc.db'
|
1630 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1631 |
def add_or_update_contact(contact_data):
|
1632 |
conn = sqlite3.connect(DATABASE_NAME3)
|
1633 |
cursor = conn.cursor()
|
|
|
1637 |
logging.error(f"Missing email in contact data: {contact_data}")
|
1638 |
return
|
1639 |
|
1640 |
+
# Добавление текущей даты и времени
|
1641 |
+
utc_now = datetime.utcnow()
|
1642 |
+
msk_tz = pytz.timezone('Europe/Moscow')
|
1643 |
+
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
1644 |
+
contact_data['data_t'] = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
1645 |
+
|
1646 |
cursor.execute("SELECT id FROM contacts WHERE email = ?", (email,))
|
1647 |
contact = cursor.fetchone()
|
1648 |
|
|
|
1649 |
fields = [
|
1650 |
'name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog',
|
1651 |
'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator',
|
|
|
1656 |
|
1657 |
if contact:
|
1658 |
update_query = f"UPDATE contacts SET {placeholders} WHERE id = ?"
|
1659 |
+
cursor.execute(update_query, (*[contact_data.get(field, '') for field in fields], contact[0]))
|
1660 |
else:
|
1661 |
insert_query = f"INSERT INTO contacts ({', '.join(fields)}) VALUES ({', '.join(['?' for _ in fields])})"
|
1662 |
+
cursor.execute(insert_query, tuple(contact_data.get(field, '') for field in fields))
|
1663 |
|
1664 |
conn.commit()
|
1665 |
conn.close()
|
1666 |
|
1667 |
@app.route('/add_data_ver', methods=['GET'])
|
1668 |
def add_data_ver():
|
|
|
1669 |
contact_data = {
|
1670 |
+
'name': request.args.get('name', ''),
|
1671 |
+
'phone': request.args.get('phone', ''),
|
1672 |
+
'email': request.args.get('email', ''),
|
1673 |
+
'vk_id': request.args.get('vk_id', ''),
|
1674 |
+
'chat_id': request.args.get('chat_id', ''),
|
1675 |
+
'ws_st': request.args.get('ws_st', ''),
|
1676 |
+
'ws_stop': request.args.get('ws_stop', ''),
|
1677 |
+
'web_st': request.args.get('web_st', ''),
|
1678 |
'fin_prog': request.args.get('fin_prog', '5'),
|
1679 |
+
'b_city': request.args.get('b_city', ''),
|
1680 |
+
'b_fin': request.args.get('b_fin', ''),
|
1681 |
+
'b_ban': request.args.get('b_ban', ''),
|
1682 |
+
'b_ign': request.args.get('b_ign', ''),
|
1683 |
+
'b_baners': request.args.get('b_baners', ''),
|
1684 |
+
'b_butt': request.args.get('b_butt', ''),
|
1685 |
+
'b_mess': request.args.get('b_mess', ''),
|
1686 |
+
'shop_st': request.args.get('shop_st', ''),
|
1687 |
+
'curator': request.args.get('curator', ''),
|
1688 |
+
'pr1': request.args.get('pr1', ''),
|
1689 |
+
'pr2': request.args.get('pr2', ''),
|
1690 |
+
'pr3': request.args.get('pr3', ''),
|
1691 |
+
'pr4': request.args.get('pr4', ''),
|
1692 |
+
'pr5': request.args.get('pr5', ''),
|
1693 |
+
'ad_url': request.args.get('ad_url', ''),
|
1694 |
+
'key_pr': request.args.get('key_pr', ''),
|
1695 |
+
'n_con': request.args.get('n_con', ''),
|
1696 |
+
'canal': request.args.get('canal', ''),
|
1697 |
+
'data_t': '' # Будет заполнено в функции add_or_update_contact
|
1698 |
}
|
1699 |
|
|
|
1700 |
phone_verification_response = verify_phone_number(contact_data['phone'])
|
1701 |
if phone_verification_response is not None:
|
1702 |
+
contact_data['ws_st'] = phone_verification_response
|
1703 |
|
1704 |
try:
|
1705 |
add_or_update_contact(contact_data)
|