DmitrMakeev commited on
Commit
b010f8d
1 Parent(s): 2819cf3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -34
app.py CHANGED
@@ -782,6 +782,8 @@ def send_request():
782
 
783
  DATABASE_NAME = 'data_gc.db'
784
 
 
 
785
  def update_or_insert_user(db_name, user_data, mapping_template):
786
  conn = sqlite3.connect(db_name)
787
  cursor = conn.cursor()
@@ -821,10 +823,8 @@ def update_or_insert_user(db_name, user_data, mapping_template):
821
  transformed_data['phone'] = phone
822
  logging.debug(f"Transformed data after phone processing: {transformed_data}")
823
 
824
- web_st_value = 0
825
- if user:
826
- web_st_value = 1 if user[0] is None or user[0] == "" or user[0] == 0 else int(user[0])
827
- web_st_value += 1
828
  logging.debug(f"Calculated web_st_value: {web_st_value}")
829
 
830
  update_query = "UPDATE contacts SET "
@@ -832,8 +832,8 @@ def update_or_insert_user(db_name, user_data, mapping_template):
832
  for column, value in transformed_data.items():
833
  update_query += f"{column} = ?, "
834
  update_values.append(value)
835
- update_query += "web_st = ? WHERE email = ?"
836
- update_values.extend([web_st_value, email])
837
  logging.debug(f"Update query: {update_query} with values: {update_values}")
838
  cursor.execute(update_query, update_values)
839
 
@@ -849,42 +849,24 @@ def update_or_insert_user(db_name, user_data, mapping_template):
849
  conn.close()
850
  logging.debug(f"User with email {email} processed successfully")
851
 
852
- @app.route('/send_get_request', methods=['GET'])
853
- def send_get_request():
854
- token = request.args.get('token')
855
- webinarId = request.args.get('webinarId')
856
- url = f'https://online.bizon365.ru/api/v1/webinars/reports/get?webinarId={webinarId}'
857
 
858
- response = requests.get(url, headers={'X-Token': token})
859
 
860
- if response.status_code == 200:
861
- data = response.json()
862
 
863
- report = data.get('report', {})
864
- messages = data.get('messages', {})
865
 
866
- report_json_str = report.get('report', '{}')
867
- try:
868
- report_json = json.loads(report_json_str)
869
- except json.JSONDecodeError:
870
- report_json = {}
871
 
872
- messages_json_str = report.get('messages', '{}')
873
- try:
874
- messages_json = json.loads(messages_json_str)
875
- except json.JSONDecodeError:
876
- messages_json = {}
877
 
878
- users_meta = report_json.get('usersMeta', {})
879
 
880
- # Обновление или добавление каждого пользователя в базу данных data_gc.db
881
- for user_id, user_data in users_meta.items():
882
- user_data['messages'] = messages_json
883
- update_or_insert_user(DATABASE_NAME, user_data, mapping_template)
884
 
885
- return jsonify({'status': 'User data saved successfully'})
886
- else:
887
- return jsonify({'error': 'Failed to fetch data from the API'}), response.status_code
 
 
 
 
 
 
 
888
 
889
 
890
 
 
782
 
783
  DATABASE_NAME = 'data_gc.db'
784
 
785
+
786
+
787
  def update_or_insert_user(db_name, user_data, mapping_template):
788
  conn = sqlite3.connect(db_name)
789
  cursor = conn.cursor()
 
823
  transformed_data['phone'] = phone
824
  logging.debug(f"Transformed data after phone processing: {transformed_data}")
825
 
826
+ # Увеличиваем значение web_st на единицу
827
+ web_st_value = 1
 
 
828
  logging.debug(f"Calculated web_st_value: {web_st_value}")
829
 
830
  update_query = "UPDATE contacts SET "
 
832
  for column, value in transformed_data.items():
833
  update_query += f"{column} = ?, "
834
  update_values.append(value)
835
+ update_query += "web_st = web_st + 1 WHERE email = ?"
836
+ update_values.append(email)
837
  logging.debug(f"Update query: {update_query} with values: {update_values}")
838
  cursor.execute(update_query, update_values)
839
 
 
849
  conn.close()
850
  logging.debug(f"User with email {email} processed successfully")
851
 
 
 
 
 
 
852
 
 
853
 
 
 
854
 
 
 
855
 
 
 
 
 
 
856
 
 
 
 
 
 
857
 
 
858
 
 
 
 
 
859
 
860
+
861
+
862
+
863
+
864
+
865
+
866
+
867
+
868
+
869
+
870
 
871
 
872