DmitrMakeev commited on
Commit
ae929a2
·
verified ·
1 Parent(s): f85174e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -4
app.py CHANGED
@@ -72,7 +72,7 @@ if not os.path.exists(HTML_FOLDER):
72
 
73
 
74
 
75
- DATABASES = ['data_gc.db', 'data1.db', 'data2.db', 'data3.db', 'data4.db', 'data5.db']
76
 
77
 
78
 
@@ -283,7 +283,7 @@ mapp_templates = {
283
  'quest': tl_quest
284
  }
285
 
286
- DATABASE_NAME3 = 'data_gc.db'
287
  def verify_phone_number(phone_number):
288
  full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
289
  payload = {"phoneNumber": phone_number}
@@ -341,8 +341,8 @@ def add_or_update_contact(contact_data, db_name):
341
 
342
 
343
 
344
- @app.route('/wr_user_ver_cur', methods=['GET'])
345
- def add_user_ver_cur():
346
  global current_curator_index
347
 
348
  veref_on_off = request.args.get('ver', '0')
@@ -381,7 +381,45 @@ def add_user_ver_cur():
381
  logging.error(f"Error adding user: {e}")
382
  return jsonify({'status': 'error', 'message': str(e)}), 500
383
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
 
 
 
 
 
 
 
385
 
386
 
387
 
 
72
 
73
 
74
 
75
+ DATABASES = ['data_gc.db', 'site_data.db', 'ws_data.db', 'vk_data.db', 'tg_data.db', 'gk_data.db']
76
 
77
 
78
 
 
283
  'quest': tl_quest
284
  }
285
 
286
+
287
  def verify_phone_number(phone_number):
288
  full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
289
  payload = {"phoneNumber": phone_number}
 
341
 
342
 
343
 
344
+ @app.route('/add_user_home', methods=['GET'])
345
+ def add_user_home():
346
  global current_curator_index
347
 
348
  veref_on_off = request.args.get('ver', '0')
 
381
  logging.error(f"Error adding user: {e}")
382
  return jsonify({'status': 'error', 'message': str(e)}), 500
383
 
384
+ @app.route('/add_user_mess', methods=['GET'])
385
+ def add_user_mess():
386
+ global current_curator_index
387
+
388
+ veref_on_off = request.args.get('ver', '0')
389
+ curator_on_off = request.args.get('cur', '0')
390
+ db_name = request.args.get('db', 'site_data.db') # Получаем имя базы данных из запроса
391
+
392
+ template_key = request.args.get('player', 'site')
393
+ mapping_template_cur = mapp_templates.get(template_key, mt_site)
394
+
395
+ user_data = {mapping_template_cur[key]: request.args.get(key, "") for key in mapping_template_cur}
396
+
397
+ logging.debug(f"Received data: {user_data}")
398
+
399
+ if curator_on_off == "1":
400
+ user_data['curator'] = curators[current_curator_index]
401
+ current_curator_index = (current_curator_index + 1) % len(curators)
402
+ else:
403
+ user_data['curator'] = user_data.get('curator', '')
404
+
405
+ if veref_on_off == "1":
406
+ phone_number = user_data.get('phone', '')
407
+ if not phone_number:
408
+ logging.error("Phone number is empty")
409
+ return jsonify({'status': 'error', 'message': 'Phone number is empty'}), 400
410
+
411
+ phone_verification_response = verify_phone_number(phone_number)
412
+ if phone_verification_response is not None:
413
+ user_data['ws_st'] = '1' if phone_verification_response else '0'
414
+ else:
415
+ user_data['ws_st'] = user_data.get('ws_st', '')
416
 
417
+ try:
418
+ add_or_update_contact(user_data, db_name)
419
+ return jsonify({'status': 'success', 'message': f'User added {user_data.get("curator", "not assigned")}'})
420
+ except Exception as e:
421
+ logging.error(f"Error adding user: {e}")
422
+ return jsonify({'status': 'error', 'message': str(e)}), 500
423
 
424
 
425