Update app.py
Browse files
app.py
CHANGED
|
@@ -810,14 +810,16 @@ def verify_phone_number_biz(phone_number):
|
|
| 810 |
full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
|
| 811 |
payload = {"phoneNumber": phone_number}
|
| 812 |
headers = {'Content-Type': 'application/json'}
|
| 813 |
-
|
| 814 |
-
|
|
|
|
| 815 |
response_body = response.json()
|
|
|
|
| 816 |
return response_body.get('existsWhatsapp', 'false')
|
| 817 |
-
|
|
|
|
| 818 |
return "Error"
|
| 819 |
|
| 820 |
-
|
| 821 |
def update_or_insert_user_biz(db_name, user_data, mapping_template):
|
| 822 |
conn = sqlite3.connect(db_name)
|
| 823 |
cursor = conn.cursor()
|
|
@@ -841,15 +843,10 @@ def update_or_insert_user_biz(db_name, user_data, mapping_template):
|
|
| 841 |
|
| 842 |
cursor.execute("UPDATE contacts SET web_st = ? WHERE email = ?", (web_st_value, email))
|
| 843 |
conn.commit()
|
| 844 |
-
conn.close()
|
| 845 |
logging.debug(f"User {email} web_st updated to {web_st_value}")
|
| 846 |
else:
|
| 847 |
-
conn.close()
|
| 848 |
logging.debug(f"User {email} not found, proceeding with insert")
|
| 849 |
|
| 850 |
-
conn = sqlite3.connect(db_name)
|
| 851 |
-
cursor = conn.cursor()
|
| 852 |
-
|
| 853 |
transformed_data = {}
|
| 854 |
for json_key, db_column in mapping_template.items():
|
| 855 |
value = user_data.get(json_key, "")
|
|
@@ -887,18 +884,19 @@ def update_or_insert_user_biz(db_name, user_data, mapping_template):
|
|
| 887 |
# Верификация номера телефона
|
| 888 |
if 'phone' in user_data and verifikation_start == "1":
|
| 889 |
phone_verification_result = verify_phone_number_biz(transformed_data['phone'])
|
| 890 |
-
logging.debug(f"Phone verification result for {email}: {phone_verification_result}")
|
| 891 |
if phone_verification_result == "true":
|
| 892 |
transformed_data['ws_st'] = "True"
|
| 893 |
else:
|
| 894 |
transformed_data['ws_st'] = "False"
|
|
|
|
| 895 |
|
| 896 |
# Назначение куратора
|
| 897 |
if curator_on_off == "1":
|
| 898 |
global current_curator_index
|
| 899 |
transformed_data['curator'] = curators[current_curator_index]
|
| 900 |
current_curator_index = (current_curator_index + 1) % len(curators)
|
| 901 |
-
logging.debug(f"Curator assigned for {email}: {transformed_data['curator']}")
|
| 902 |
|
| 903 |
if user:
|
| 904 |
update_query = "UPDATE contacts SET "
|
|
@@ -1016,8 +1014,7 @@ def webhookbz_biz():
|
|
| 1016 |
|
| 1017 |
return jsonify({'status': 'User data saved successfully'})
|
| 1018 |
else:
|
| 1019 |
-
return jsonify({'error': 'Failed to fetch data from the API'}),
|
| 1020 |
-
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
|
|
|
| 810 |
full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
|
| 811 |
payload = {"phoneNumber": phone_number}
|
| 812 |
headers = {'Content-Type': 'application/json'}
|
| 813 |
+
try:
|
| 814 |
+
response = requests.post(full_url_ver, headers=headers, json=payload)
|
| 815 |
+
response.raise_for_status()
|
| 816 |
response_body = response.json()
|
| 817 |
+
logging.debug(f"Phone verification response: {response_body}")
|
| 818 |
return response_body.get('existsWhatsapp', 'false')
|
| 819 |
+
except requests.RequestException as e:
|
| 820 |
+
logging.error(f"Error during phone verification: {str(e)}")
|
| 821 |
return "Error"
|
| 822 |
|
|
|
|
| 823 |
def update_or_insert_user_biz(db_name, user_data, mapping_template):
|
| 824 |
conn = sqlite3.connect(db_name)
|
| 825 |
cursor = conn.cursor()
|
|
|
|
| 843 |
|
| 844 |
cursor.execute("UPDATE contacts SET web_st = ? WHERE email = ?", (web_st_value, email))
|
| 845 |
conn.commit()
|
|
|
|
| 846 |
logging.debug(f"User {email} web_st updated to {web_st_value}")
|
| 847 |
else:
|
|
|
|
| 848 |
logging.debug(f"User {email} not found, proceeding with insert")
|
| 849 |
|
|
|
|
|
|
|
|
|
|
| 850 |
transformed_data = {}
|
| 851 |
for json_key, db_column in mapping_template.items():
|
| 852 |
value = user_data.get(json_key, "")
|
|
|
|
| 884 |
# Верификация номера телефона
|
| 885 |
if 'phone' in user_data and verifikation_start == "1":
|
| 886 |
phone_verification_result = verify_phone_number_biz(transformed_data['phone'])
|
| 887 |
+
logging.debug(f"Phone verification result for {email}: {phone_verification_result}")
|
| 888 |
if phone_verification_result == "true":
|
| 889 |
transformed_data['ws_st'] = "True"
|
| 890 |
else:
|
| 891 |
transformed_data['ws_st'] = "False"
|
| 892 |
+
logging.debug(f"Transformed data after phone verification: {transformed_data}")
|
| 893 |
|
| 894 |
# Назначение куратора
|
| 895 |
if curator_on_off == "1":
|
| 896 |
global current_curator_index
|
| 897 |
transformed_data['curator'] = curators[current_curator_index]
|
| 898 |
current_curator_index = (current_curator_index + 1) % len(curators)
|
| 899 |
+
logging.debug(f"Curator assigned for {email}: {transformed_data['curator']}")
|
| 900 |
|
| 901 |
if user:
|
| 902 |
update_query = "UPDATE contacts SET "
|
|
|
|
| 1014 |
|
| 1015 |
return jsonify({'status': 'User data saved successfully'})
|
| 1016 |
else:
|
| 1017 |
+
return jsonify({'error': 'Failed to fetch data from the API'}), 500
|
|
|
|
| 1018 |
|
| 1019 |
|
| 1020 |
|