DmitrMakeev commited on
Commit
10cad6e
1 Parent(s): ecb0b93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -861,7 +861,46 @@ def update_or_insert_user(db_name, user_data, mapping_template):
861
 
862
 
863
 
 
 
 
 
 
864
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
865
 
866
 
867
 
 
861
 
862
 
863
 
864
+ @app.route('/send_get_request', methods=['GET'])
865
+ def send_get_request():
866
+ token = request.args.get('token')
867
+ webinarId = request.args.get('webinarId')
868
+ url = f'https://online.bizon365.ru/api/v1/webinars/reports/get?webinarId={webinarId}'
869
 
870
+ response = requests.get(url, headers={'X-Token': token})
871
+
872
+ if response.status_code == 200:
873
+ data = response.json()
874
+
875
+ report = data.get('report', {})
876
+ messages = data.get('messages', {})
877
+
878
+ report_json_str = report.get('report', '{}')
879
+ try:
880
+ report_json = json.loads(report_json_str)
881
+ except json.JSONDecodeError:
882
+ report_json = {}
883
+
884
+ messages_json_str = report.get('messages', '{}')
885
+ try:
886
+ messages_json = json.loads(messages_json_str)
887
+ except json.JSONDecodeError:
888
+ messages_json = {}
889
+
890
+ users_meta = report_json.get('usersMeta', {})
891
+
892
+ # Обновление или добавление каждого пользователя в базу данных data_gc.db
893
+ processed_emails = set()
894
+ for user_id, user_data in users_meta.items():
895
+ user_data['messages'] = messages_json
896
+ email = user_data.get('email')
897
+ if email not in processed_emails:
898
+ update_or_insert_user(DATABASE_NAME, user_data, mapping_template)
899
+ processed_emails.add(email)
900
+
901
+ return jsonify({'status': 'User data saved successfully'})
902
+ else:
903
+ return jsonify({'error': 'Failed to fetch data from the API'}), response.status_code
904
 
905
 
906