DmitrMakeev commited on
Commit
e40dcb7
·
verified ·
1 Parent(s): 1502d60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -772,10 +772,11 @@ def send_request():
772
  DATABASE_NAME = 'data_gc.db'
773
 
774
  def update_or_insert_user(db_name, user_data, mapping_template):
775
- conn = sqlite3.connect(db_name)
776
  cursor = conn.cursor()
777
 
778
  email = user_data.get('email')
 
779
 
780
  cursor.execute("SELECT web_st FROM contacts WHERE email = ?", (email,))
781
  user = cursor.fetchone()
@@ -794,8 +795,8 @@ def update_or_insert_user(db_name, user_data, mapping_template):
794
  update_values.extend([web_st_value, email])
795
  cursor.execute(update_query, update_values)
796
  else:
797
- columns = ', '.join(mapping_template.values()) + ", web_st"
798
- placeholders = ', '.join('?' for _ in mapping_template) + ", ?"
799
  insert_query = f"INSERT INTO contacts ({columns}) VALUES ({placeholders})"
800
  insert_values = []
801
  for json_key, db_column in mapping_template.items():
@@ -803,7 +804,7 @@ def update_or_insert_user(db_name, user_data, mapping_template):
803
  if isinstance(value, list):
804
  value = "-1" if value else "0"
805
  insert_values.append(str(value))
806
- insert_values.append(0)
807
  cursor.execute(insert_query, insert_values)
808
 
809
  conn.commit()
@@ -837,7 +838,6 @@ def send_get_request():
837
 
838
  users_meta = report_json.get('usersMeta', {})
839
 
840
- # Обновление или добавление каждого пользователя в базу данных data_gc.db
841
  for user_id, user_data in users_meta.items():
842
  user_data['messages'] = messages_json
843
  update_or_insert_user(DATABASE_NAME, user_data, mapping_template)
@@ -865,7 +865,6 @@ def send_get_request():
865
 
866
 
867
 
868
-
869
 
870
 
871
  @app.route('/biz_v', methods=['GET'])
 
772
  DATABASE_NAME = 'data_gc.db'
773
 
774
  def update_or_insert_user(db_name, user_data, mapping_template):
775
+ conn = sqlite3.connect(db_name, timeout=10, check_same_thread=False)
776
  cursor = conn.cursor()
777
 
778
  email = user_data.get('email')
779
+ vk_id = user_data.get('vk_id', 'default_vk_id') # Используйте значение по умолчанию для vk_id
780
 
781
  cursor.execute("SELECT web_st FROM contacts WHERE email = ?", (email,))
782
  user = cursor.fetchone()
 
795
  update_values.extend([web_st_value, email])
796
  cursor.execute(update_query, update_values)
797
  else:
798
+ columns = ', '.join(mapping_template.values()) + ", web_st, vk_id"
799
+ placeholders = ', '.join('?' for _ in mapping_template) + ", ?, ?"
800
  insert_query = f"INSERT INTO contacts ({columns}) VALUES ({placeholders})"
801
  insert_values = []
802
  for json_key, db_column in mapping_template.items():
 
804
  if isinstance(value, list):
805
  value = "-1" if value else "0"
806
  insert_values.append(str(value))
807
+ insert_values.extend([0, vk_id])
808
  cursor.execute(insert_query, insert_values)
809
 
810
  conn.commit()
 
838
 
839
  users_meta = report_json.get('usersMeta', {})
840
 
 
841
  for user_id, user_data in users_meta.items():
842
  user_data['messages'] = messages_json
843
  update_or_insert_user(DATABASE_NAME, user_data, mapping_template)
 
865
 
866
 
867
 
 
868
 
869
 
870
  @app.route('/biz_v', methods=['GET'])