DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -48,7 +48,7 @@ code_executed = False
|
|
48 |
status = "active"
|
49 |
|
50 |
|
51 |
-
|
52 |
|
53 |
|
54 |
|
@@ -1632,16 +1632,15 @@ mapping_template_cur = {
|
|
1632 |
}
|
1633 |
|
1634 |
DATABASE_NAME3 = 'data_gc.db'
|
1635 |
-
verifikation_start = "1" # Пример значения, которое должно быть установлено из конфигурации
|
1636 |
-
|
1637 |
-
|
1638 |
def verify_phone_number(phone_number):
|
1639 |
-
|
1640 |
print(f"verifikation_start: {verifikation_start}")
|
1641 |
|
1642 |
if verifikation_start == "1":
|
|
|
|
|
1643 |
full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
|
1644 |
-
print(f"Full URL
|
1645 |
|
1646 |
# Создаем payload для запроса
|
1647 |
payload = json.dumps({
|
@@ -1655,13 +1654,13 @@ def verify_phone_number(phone_number):
|
|
1655 |
response = requests.post(full_url_ver, headers=headers, data=payload)
|
1656 |
|
1657 |
# Печатаем статус ответа
|
1658 |
-
print(f"Response Status Code
|
1659 |
|
1660 |
# Проверяем статус код ответа
|
1661 |
if response.status_code == 200:
|
1662 |
# Печатаем текст ответа от сервера
|
1663 |
response_body = response.json()
|
1664 |
-
print(f"Response Body
|
1665 |
|
1666 |
# Извлекаем значение из JSON
|
1667 |
exists_whatsapp = response_body.get('existsWhatsapp', 'false')
|
@@ -1670,35 +1669,44 @@ def verify_phone_number(phone_number):
|
|
1670 |
# Возвращаем значение
|
1671 |
return exists_whatsapp
|
1672 |
else:
|
1673 |
-
print("Error: Unable to fetch data
|
1674 |
return "Error"
|
1675 |
else:
|
1676 |
print("Verification not started")
|
1677 |
return "false" # Возвращаем значение, что WhatsApp не существует
|
1678 |
-
|
1679 |
-
|
1680 |
-
conn = sqlite3.connect(db_name)
|
1681 |
cursor = conn.cursor()
|
1682 |
|
1683 |
-
|
1684 |
-
|
|
|
|
|
1685 |
|
1686 |
-
# Добавление
|
1687 |
-
|
1688 |
-
|
1689 |
-
|
1690 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1691 |
]
|
1692 |
-
|
1693 |
-
|
1694 |
-
transformed_data[field] = ""
|
1695 |
|
1696 |
-
|
1697 |
-
|
1698 |
-
|
1699 |
-
|
|
|
|
|
1700 |
|
1701 |
-
cursor.execute(insert_query, insert_values)
|
1702 |
conn.commit()
|
1703 |
conn.close()
|
1704 |
|
|
|
48 |
status = "active"
|
49 |
|
50 |
|
51 |
+
verifikation_start = "1"
|
52 |
|
53 |
|
54 |
|
|
|
1632 |
}
|
1633 |
|
1634 |
DATABASE_NAME3 = 'data_gc.db'
|
|
|
|
|
|
|
1635 |
def verify_phone_number(phone_number):
|
1636 |
+
|
1637 |
print(f"verifikation_start: {verifikation_start}")
|
1638 |
|
1639 |
if verifikation_start == "1":
|
1640 |
+
|
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({
|
|
|
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')
|
|
|
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 "false" # Возвращаем значение, что WhatsApp не существует
|
1677 |
+
def add_or_update_contact(contact_data):
|
1678 |
+
conn = sqlite3.connect(DATABASE_NAME3)
|
|
|
1679 |
cursor = conn.cursor()
|
1680 |
|
1681 |
+
email = contact_data.get('email')
|
1682 |
+
if not email:
|
1683 |
+
logging.error(f"Missing email in contact data: {contact_data}")
|
1684 |
+
return
|
1685 |
|
1686 |
+
# Добавление текущей даты и времени
|
1687 |
+
utc_now = datetime.utcnow()
|
1688 |
+
msk_tz = pytz.timezone('Europe/Moscow')
|
1689 |
+
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
1690 |
+
contact_data['data_t'] = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
1691 |
+
|
1692 |
+
cursor.execute("SELECT id FROM contacts WHERE email = ?", (email,))
|
1693 |
+
contact = cursor.fetchone()
|
1694 |
+
|
1695 |
+
fields = [
|
1696 |
+
'name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog',
|
1697 |
+
'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator',
|
1698 |
+
'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'ad_url', 'key_pr', 'n_con', 'canal', 'data_t'
|
1699 |
]
|
1700 |
+
|
1701 |
+
placeholders = ", ".join([f"{field} = ?" for field in fields])
|
|
|
1702 |
|
1703 |
+
if contact:
|
1704 |
+
update_query = f"UPDATE contacts SET {placeholders} WHERE id = ?"
|
1705 |
+
cursor.execute(update_query, (*[contact_data.get(field, '') for field in fields], contact[0]))
|
1706 |
+
else:
|
1707 |
+
insert_query = f"INSERT INTO contacts ({', '.join(fields)}) VALUES ({', '.join(['?' for _ in fields])})"
|
1708 |
+
cursor.execute(insert_query, tuple(contact_data.get(field, '') for field in fields))
|
1709 |
|
|
|
1710 |
conn.commit()
|
1711 |
conn.close()
|
1712 |
|