DmitrMakeev
commited on
Commit
•
0cebab8
1
Parent(s):
392516a
Update app.py
Browse files
app.py
CHANGED
@@ -1766,106 +1766,31 @@ def add_data_ver_cur():
|
|
1766 |
|
1767 |
|
1768 |
|
1769 |
-
|
1770 |
-
|
1771 |
-
|
1772 |
-
'phone': 'phone',
|
1773 |
-
'email': 'email'
|
1774 |
-
}
|
1775 |
-
|
1776 |
-
DATABASE_NAME4 = 'data_gc.db'
|
1777 |
-
|
1778 |
-
|
1779 |
-
def verify_phone_number_v2(phone_number):
|
1780 |
-
print(f"verifikation_start: {verifikation_start}")
|
1781 |
-
|
1782 |
-
if verifikation_start == "1":
|
1783 |
-
full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
|
1784 |
-
print(f"Full URL: {full_url_ver}")
|
1785 |
-
|
1786 |
-
# Создаем payload для запроса
|
1787 |
-
payload = json.dumps({
|
1788 |
-
"phoneNumber": phone_number
|
1789 |
-
})
|
1790 |
-
headers = {
|
1791 |
-
'Content-Type': 'application/json'
|
1792 |
-
}
|
1793 |
-
|
1794 |
-
# Отправляем POST-запрос
|
1795 |
-
response = requests.post(full_url_ver, headers=headers, data=payload)
|
1796 |
-
|
1797 |
-
# Печатаем статус ответа
|
1798 |
-
print(f"Response Status Code: {response.status_code}")
|
1799 |
-
|
1800 |
-
# Проверяем статус код ответа
|
1801 |
-
if response.status_code == 200:
|
1802 |
-
# Печатаем текст ответа от сервера
|
1803 |
-
response_body = response.json()
|
1804 |
-
print(f"Response Body: {response_body}")
|
1805 |
-
|
1806 |
-
# Извлекаем значение из JSON
|
1807 |
-
exists_whatsapp = response_body.get('existsWhatsapp', 'false')
|
1808 |
-
print(f"existsWhatsapp: {exists_whatsapp}")
|
1809 |
-
|
1810 |
-
# Возвращаем значение
|
1811 |
-
return exists_whatsapp
|
1812 |
-
else:
|
1813 |
-
print("Error: Unable to fetch data")
|
1814 |
-
return "Error"
|
1815 |
-
else:
|
1816 |
-
print("Verification not started")
|
1817 |
-
return "false" # Возвращаем значение, что WhatsApp не существует
|
1818 |
-
|
1819 |
-
def add_or_update_contact(contact_data):
|
1820 |
-
conn = sqlite3.connect(DATABASE_NAME4)
|
1821 |
-
cursor = conn.cursor()
|
1822 |
-
|
1823 |
-
email = contact_data.get('email')
|
1824 |
-
if not email:
|
1825 |
-
logging.error(f"Missing email in contact data: {contact_data}")
|
1826 |
-
return
|
1827 |
-
|
1828 |
-
# Добавление текущей даты и времени
|
1829 |
-
utc_now = datetime.utcnow()
|
1830 |
-
msk_tz = pytz.timezone('Europe/Moscow')
|
1831 |
-
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
1832 |
-
contact_data['data_t'] = msk_now.strftime('%Y-%m-%d %H:%M:%S')
|
1833 |
-
|
1834 |
-
cursor.execute("SELECT id FROM contacts WHERE email = ?", (email,))
|
1835 |
-
contact = cursor.fetchone()
|
1836 |
|
1837 |
-
|
1838 |
-
|
1839 |
-
'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator',
|
1840 |
-
'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'ad_url', 'key_pr', 'n_con', 'canal', 'data_t'
|
1841 |
-
]
|
1842 |
|
1843 |
-
|
1844 |
-
|
1845 |
-
if contact:
|
1846 |
-
update_query = f"UPDATE contacts SET {placeholders} WHERE id = ?"
|
1847 |
-
cursor.execute(update_query, (*[contact_data.get(field, '') for field in fields], contact[0]))
|
1848 |
-
else:
|
1849 |
-
insert_query = f"INSERT INTO contacts ({', '.join(fields)}) VALUES ({', '.join(['?' for _ in fields])})"
|
1850 |
-
cursor.execute(insert_query, tuple(contact_data.get(field, '') for field in fields))
|
1851 |
|
1852 |
-
|
1853 |
-
conn.close()
|
1854 |
|
1855 |
-
|
1856 |
-
|
1857 |
-
# Получаем данные пользователя из параметров запроса
|
1858 |
-
user_data = {key: request.args.get(key, "") for key in mapping_template_cur.keys()}
|
1859 |
|
1860 |
-
|
1861 |
-
|
1862 |
-
|
1863 |
-
|
1864 |
|
1865 |
try:
|
1866 |
-
# Добавляем пользователя в базу данных
|
1867 |
add_or_update_contact(user_data)
|
1868 |
-
|
|
|
|
|
1869 |
except Exception as e:
|
1870 |
logging.error(f"Error adding user: {e}")
|
1871 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
@@ -1896,7 +1821,6 @@ def add_data_bot():
|
|
1896 |
|
1897 |
|
1898 |
|
1899 |
-
|
1900 |
|
1901 |
|
1902 |
initialize_requests()
|
|
|
1766 |
|
1767 |
|
1768 |
|
1769 |
+
@app.route('/gc_in', methods=['GET'])
|
1770 |
+
def add_data_gc_in():
|
1771 |
+
global current_curator_index
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1772 |
|
1773 |
+
veref_on_off = request.args.get('ver', '0') # Включает "1" и выключает "0" верификацию номера вместо verifikation_start
|
1774 |
+
curator_on_off = request.args.get('cur', '0') # Включает "1" и выключает "0" назначение куратора
|
|
|
|
|
|
|
1775 |
|
1776 |
+
template_key = request.args.get('template_key', 'avp')
|
1777 |
+
mapping_template_cur = mapp_templates.get(template_key, mt_avp)
|
|
|
|
|
|
|
|
|
|
|
|
|
1778 |
|
1779 |
+
user_data = {mapping_template_cur[key]: request.args.get(key, "") for key in mapping_template_cur}
|
|
|
1780 |
|
1781 |
+
if curator_on_off == "1":
|
1782 |
+
user_data['curator'] = curators[current_curator_index]
|
|
|
|
|
1783 |
|
1784 |
+
if veref_on_off == "1":
|
1785 |
+
phone_verification_response = verify_phone_number(user_data.get('phone', ''))
|
1786 |
+
if phone_verification_response is not None:
|
1787 |
+
user_data['ws_st'] = phone_verification_response
|
1788 |
|
1789 |
try:
|
|
|
1790 |
add_or_update_contact(user_data)
|
1791 |
+
if curator_on_off == "1":
|
1792 |
+
current_curator_index = (current_curator_index + 1) % len(curators)
|
1793 |
+
return jsonify({'status': 'success', 'message': f'User added with curator {user_data.get("curator", "not assigned")}'})
|
1794 |
except Exception as e:
|
1795 |
logging.error(f"Error adding user: {e}")
|
1796 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
|
|
1821 |
|
1822 |
|
1823 |
|
|
|
1824 |
|
1825 |
|
1826 |
initialize_requests()
|