DmitrMakeev
commited on
Commit
•
ecb0b93
1
Parent(s):
910e31e
Update app.py
Browse files
app.py
CHANGED
@@ -858,43 +858,6 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
858 |
conn.close()
|
859 |
logging.debug(f"User with email {email} processed successfully")
|
860 |
|
861 |
-
@app.route('/send_get_request', methods=['GET'])
|
862 |
-
def send_get_request():
|
863 |
-
token = request.args.get('token')
|
864 |
-
webinarId = request.args.get('webinarId')
|
865 |
-
url = f'https://online.bizon365.ru/api/v1/webinars/reports/get?webinarId={webinarId}'
|
866 |
-
|
867 |
-
response = requests.get(url, headers={'X-Token': token})
|
868 |
-
|
869 |
-
if response.status_code == 200:
|
870 |
-
data = response.json()
|
871 |
-
|
872 |
-
report = data.get('report', {})
|
873 |
-
messages = data.get('messages', {})
|
874 |
-
|
875 |
-
report_json_str = report.get('report', '{}')
|
876 |
-
try:
|
877 |
-
report_json = json.loads(report_json_str)
|
878 |
-
except json.JSONDecodeError:
|
879 |
-
report_json = {}
|
880 |
-
|
881 |
-
messages_json_str = report.get('messages', '{}')
|
882 |
-
try:
|
883 |
-
messages_json = json.loads(messages_json_str)
|
884 |
-
except json.JSONDecodeError:
|
885 |
-
messages_json = {}
|
886 |
-
|
887 |
-
users_meta = report_json.get('usersMeta', {})
|
888 |
-
|
889 |
-
# Обновление или добавление каждого пользователя в базу данных data_gc.db
|
890 |
-
for user_id, user_data in users_meta.items():
|
891 |
-
user_data['messages'] = messages_json
|
892 |
-
update_or_insert_user(DATABASE_NAME, user_data, mapping_template)
|
893 |
-
|
894 |
-
return jsonify({'status': 'User data saved successfully'})
|
895 |
-
else:
|
896 |
-
return jsonify({'error': 'Failed to fetch data from the API'}), response.status_code
|
897 |
-
|
898 |
|
899 |
|
900 |
|
|
|
858 |
conn.close()
|
859 |
logging.debug(f"User with email {email} processed successfully")
|
860 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
861 |
|
862 |
|
863 |
|