DmitrMakeev commited on
Commit
a949fbe
1 Parent(s): f4372e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -1556,34 +1556,32 @@ def add_or_update_contact_v2(contact_data):
1556
  msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
1557
  contact_data['data_t'] = msk_now.strftime('%Y-%m-%d %H:%M:%S')
1558
 
1559
- cursor.execute("SELECT id FROM contacts WHERE email = ?", (email,))
1560
- contact = cursor.fetchone()
1561
-
1562
  fields = [
1563
  'name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog',
1564
  'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator',
1565
  'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'gc_url', 'key_pr', 'n_con', 'canal', 'data_t', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'
1566
  ]
1567
 
 
 
 
 
 
1568
  placeholders = ", ".join([f"{field} = ?" for field in fields])
1569
 
 
 
 
1570
  if contact:
1571
  update_query = f"UPDATE contacts SET {placeholders} WHERE id = ?"
1572
- cursor.execute(update_query, (*[contact_data.get(field, '') for field in fields], contact[0]))
1573
  else:
1574
  insert_query = f"INSERT INTO contacts ({', '.join(fields)}) VALUES ({', '.join(['?' for _ in fields])})"
1575
- cursor.execute(insert_query, tuple(contact_data.get(field, '') for field in fields))
1576
 
1577
  conn.commit()
1578
  conn.close()
1579
- def send_to_google_forms_v2(user_data, gog_url):
1580
- logging.debug(f"Sending data to Google Forms: {user_data}")
1581
- url = gog_url.format(**user_data)
1582
- response = requests.post(url)
1583
- if response.status_code == 200:
1584
- logging.debug(f"Data sent to Google Forms successfully for user: {user_data.get('email')}")
1585
- else:
1586
- logging.error(f"Failed to send data to Google Forms for user: {user_data.get('email')}. Response: {response.text}")
1587
 
1588
  @app.route('/add_data_ver_cur', methods=['GET'])
1589
  def add_data_ver_cur():
 
1556
  msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
1557
  contact_data['data_t'] = msk_now.strftime('%Y-%m-%d %H:%M:%S')
1558
 
1559
+ # Список всех возможных полей
 
 
1560
  fields = [
1561
  'name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog',
1562
  'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator',
1563
  'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'gc_url', 'key_pr', 'n_con', 'canal', 'data_t', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'
1564
  ]
1565
 
1566
+ # Устанавливаем значения по умолчанию для отсутствующих полей
1567
+ for field in fields:
1568
+ if field not in contact_data:
1569
+ contact_data[field] = ''
1570
+
1571
  placeholders = ", ".join([f"{field} = ?" for field in fields])
1572
 
1573
+ cursor.execute("SELECT id FROM contacts WHERE email = ?", (email,))
1574
+ contact = cursor.fetchone()
1575
+
1576
  if contact:
1577
  update_query = f"UPDATE contacts SET {placeholders} WHERE id = ?"
1578
+ cursor.execute(update_query, (*[contact_data[field] for field in fields], contact[0]))
1579
  else:
1580
  insert_query = f"INSERT INTO contacts ({', '.join(fields)}) VALUES ({', '.join(['?' for _ in fields])})"
1581
+ cursor.execute(insert_query, tuple(contact_data[field] for field in fields))
1582
 
1583
  conn.commit()
1584
  conn.close()
 
 
 
 
 
 
 
 
1585
 
1586
  @app.route('/add_data_ver_cur', methods=['GET'])
1587
  def add_data_ver_cur():