DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -806,6 +806,41 @@ curator_on_off = "1" # Глобальная переменная для упр
|
|
806 |
|
807 |
current_curator_index = 0
|
808 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
809 |
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}
|
@@ -968,53 +1003,6 @@ def send_get_request_biz():
|
|
968 |
except requests.exceptions.RequestException as e:
|
969 |
return jsonify({'error': f'API request failed: {str(e)}'}), 500
|
970 |
|
971 |
-
@app.route('/webhookbz', methods=['POST'])
|
972 |
-
def webhookbz_biz():
|
973 |
-
api_sys_control = request.args.get('api_sys')
|
974 |
-
if api_sys_control != api_key_sys:
|
975 |
-
return "EUR 22", 200
|
976 |
-
|
977 |
-
data = request.json
|
978 |
-
webinar_id = data.get('webinarId')
|
979 |
-
|
980 |
-
if not webinar_id:
|
981 |
-
return jsonify({'error': 'webinarId is required'}), 400
|
982 |
-
|
983 |
-
url = f'https://online.bizon365.ru/api/v1/webinars/reports/get?webinarId={webinar_id}'
|
984 |
-
response = requests.get(url, headers={'X-Token': api_key_sys})
|
985 |
-
|
986 |
-
if response.status_code == 200:
|
987 |
-
data = response.json()
|
988 |
-
|
989 |
-
report = data.get('report', {})
|
990 |
-
messages = data.get('messages', {})
|
991 |
-
|
992 |
-
report_json_str = report.get('report', '{}')
|
993 |
-
try:
|
994 |
-
report_json = json.loads(report_json_str)
|
995 |
-
except json.JSONDecodeError:
|
996 |
-
report_json = {}
|
997 |
-
|
998 |
-
messages_json_str = report.get('messages', '{}')
|
999 |
-
try:
|
1000 |
-
messages_json = json.loads(messages_json_str)
|
1001 |
-
except json.JSONDecodeError:
|
1002 |
-
messages_json = {}
|
1003 |
-
|
1004 |
-
users_meta = report_json.get('usersMeta', {})
|
1005 |
-
|
1006 |
-
processed_emails = set()
|
1007 |
-
for user_id, user_data in users_meta.items():
|
1008 |
-
user_messages = messages_json.get(user_id, [])
|
1009 |
-
user_data['messages'] = user_messages
|
1010 |
-
email = user_data.get('email')
|
1011 |
-
if email and email not in processed_emails:
|
1012 |
-
update_or_insert_user_biz(DATABASE_NAME, user_data, mapping_template)
|
1013 |
-
processed_emails.add(email)
|
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 |
|
|
|
806 |
|
807 |
current_curator_index = 0
|
808 |
|
809 |
+
import sqlite3
|
810 |
+
import requests
|
811 |
+
import json
|
812 |
+
import logging
|
813 |
+
from flask import Flask, request, jsonify
|
814 |
+
|
815 |
+
app = Flask(__name__)
|
816 |
+
|
817 |
+
DATABASE_NAME = 'data_gc.db'
|
818 |
+
|
819 |
+
verifikation_start = "1" # Глобальная переменная для управления верификацией
|
820 |
+
curator_on_off = "1" # Глобальная переменная для управления назначением куратора
|
821 |
+
current_curator_index = 0
|
822 |
+
curators = ["Curator1", "Curator2", "Curator3"] # Список кураторов
|
823 |
+
|
824 |
+
wa_url = 'https://api.whatsapp.com/send?phone=' # URL для верификации номера
|
825 |
+
wa_ak = '' # Некоторая часть URL
|
826 |
+
ws_url_ver = '' # Часть URL
|
827 |
+
wa_api_key = 'YOUR_WHATSAPP_API_KEY' # API-ключ для верификации номера
|
828 |
+
api_key_sys = 'YOUR_API_KEY' # API-ключ для системного доступа
|
829 |
+
|
830 |
+
mapping_template = {
|
831 |
+
"name": "name",
|
832 |
+
"phone": "phone",
|
833 |
+
"email": "email",
|
834 |
+
"b_city": "b_city",
|
835 |
+
"b_fin": "b_fin",
|
836 |
+
"b_ban": "b_ban",
|
837 |
+
"b_ign": "b_ign",
|
838 |
+
"b_baners": "b_baners",
|
839 |
+
"b_butt": "b_butt",
|
840 |
+
"b_mess": "b_mess"
|
841 |
+
# Добавьте все необходимые поля для маппинга
|
842 |
+
}
|
843 |
+
|
844 |
def verify_phone_number_biz(phone_number):
|
845 |
full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
|
846 |
payload = {"phoneNumber": phone_number}
|
|
|
1003 |
except requests.exceptions.RequestException as e:
|
1004 |
return jsonify({'error': f'API request failed: {str(e)}'}), 500
|
1005 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1006 |
|
1007 |
|
1008 |
|