DmitrMakeev commited on
Commit
bc8a472
1 Parent(s): 8d28e0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -36
app.py CHANGED
@@ -1627,15 +1627,10 @@ def gc_forms():
1627
 
1628
 
1629
 
1630
- # Функция для проверки номера телефона
1631
  def verify_phone_number(phone_number):
1632
  verifikation_start = os.getenv('verifikation_start')
1633
 
1634
  if verifikation_start == "1":
1635
- wa_url = os.getenv('wa_url')
1636
- wa_api_key = os.getenv('wa_api_key')
1637
- wa_ak = os.getenv('ws_ak')
1638
- ws_url_ver = "/checkWhatsapp/"
1639
 
1640
  full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
1641
 
@@ -1681,21 +1676,13 @@ def add_data_ver():
1681
  if phone.startswith('+'):
1682
  phone = phone[1:]
1683
 
1684
- # Выполнение верификации номера телефона и добавление в ws_st
1685
  ws_statys = verify_phone_number(phone)
1686
 
1687
- # Получение текущего времени в московском часовом поясе
1688
  utc_now = datetime.utcnow()
1689
  msk_tz = pytz.timezone('Europe/Moscow')
1690
  msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
1691
  data_t = msk_now.strftime('%Y-%m-%d %H:%M:%S')
1692
 
1693
- conn = sqlite3.connect('data_gc.db')
1694
- cursor = conn.cursor()
1695
- cursor.execute('SELECT * FROM contacts WHERE phone = ? OR email = ?', (phone, email))
1696
- existing_contact = cursor.fetchone()
1697
-
1698
- # Преобразование данных пользователя для вставки
1699
  user_data = {
1700
  "name": name,
1701
  "phone": phone,
@@ -1707,31 +1694,50 @@ def add_data_ver():
1707
  "pr4": pr4,
1708
  "pr5": pr5,
1709
  "canal": canal,
1710
- "data_t": data_t
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1711
  }
1712
 
1713
- # Обработка полей, которые могут быть NULL
1714
- for field in ["vk_id", "chat_id", "ws_stop", "web_st", "fin_prog", "shop_st", "ad_url", "curator", "key_pr", "n_con"]:
1715
- user_data[field] = ""
1716
-
1717
- if existing_contact:
1718
- update_query = "UPDATE contacts SET "
1719
- update_values = []
1720
- for column, value in user_data.items():
1721
- update_query += f"{column} = ?, "
1722
- update_values.append(value)
1723
- update_query = update_query.rstrip(", ") + " WHERE phone = ? OR email = ?"
1724
- update_values.extend([phone, email])
1725
- cursor.execute(update_query, update_values)
1726
- else:
1727
- columns = ', '.join(user_data.keys())
1728
- placeholders = ', '.join('?' for _ in user_data)
1729
- insert_query = f"INSERT INTO contacts ({columns}) VALUES ({placeholders})"
1730
- insert_values = list(user_data.values())
1731
- cursor.execute(insert_query, insert_values)
 
 
1732
 
1733
- conn.commit()
1734
- conn.close()
1735
 
1736
  return f"Contact updated/added: {name} - {phone} - {email}", 200
1737
  except Exception as e:
@@ -1752,7 +1758,6 @@ def add_data_ver():
1752
 
1753
 
1754
 
1755
-
1756
  initialize_requests()
1757
 
1758
 
 
1627
 
1628
 
1629
 
 
1630
  def verify_phone_number(phone_number):
1631
  verifikation_start = os.getenv('verifikation_start')
1632
 
1633
  if verifikation_start == "1":
 
 
 
 
1634
 
1635
  full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
1636
 
 
1676
  if phone.startswith('+'):
1677
  phone = phone[1:]
1678
 
 
1679
  ws_statys = verify_phone_number(phone)
1680
 
 
1681
  utc_now = datetime.utcnow()
1682
  msk_tz = pytz.timezone('Europe/Moscow')
1683
  msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
1684
  data_t = msk_now.strftime('%Y-%m-%d %H:%M:%S')
1685
 
 
 
 
 
 
 
1686
  user_data = {
1687
  "name": name,
1688
  "phone": phone,
 
1694
  "pr4": pr4,
1695
  "pr5": pr5,
1696
  "canal": canal,
1697
+ "data_t": data_t,
1698
+ "vk_id": "",
1699
+ "chat_id": "",
1700
+ "ws_stop": "",
1701
+ "web_st": 0,
1702
+ "fin_prog": 0,
1703
+ "b_city": "",
1704
+ "b_fin": "",
1705
+ "b_ban": "",
1706
+ "b_ign": "",
1707
+ "b_baners": "",
1708
+ "b_butt": "",
1709
+ "b_mess": "",
1710
+ "shop_st": "",
1711
+ "curator": "",
1712
+ "ad_url": "",
1713
+ "key_pr": "",
1714
+ "n_con": ""
1715
  }
1716
 
1717
+ for db_name in DATABASES:
1718
+ conn = sqlite3.connect(db_name)
1719
+ cursor = conn.cursor()
1720
+ cursor.execute('SELECT * FROM contacts WHERE phone = ? OR email = ?', (phone, email))
1721
+ existing_contact = cursor.fetchone()
1722
+
1723
+ if existing_contact:
1724
+ update_query = "UPDATE contacts SET "
1725
+ update_values = []
1726
+ for column, value in user_data.items():
1727
+ update_query += f"{column} = ?, "
1728
+ update_values.append(value)
1729
+ update_query = update_query.rstrip(", ") + " WHERE phone = ? OR email = ?"
1730
+ update_values.extend([phone, email])
1731
+ cursor.execute(update_query, update_values)
1732
+ else:
1733
+ columns = ', '.join(user_data.keys())
1734
+ placeholders = ', '.join('?' for _ in user_data)
1735
+ insert_query = f"INSERT INTO contacts ({columns}) VALUES ({placeholders})"
1736
+ insert_values = list(user_data.values())
1737
+ cursor.execute(insert_query, insert_values)
1738
 
1739
+ conn.commit()
1740
+ conn.close()
1741
 
1742
  return f"Contact updated/added: {name} - {phone} - {email}", 200
1743
  except Exception as e:
 
1758
 
1759
 
1760
 
 
1761
  initialize_requests()
1762
 
1763