DmitrMakeev commited on
Commit
d987882
·
verified ·
1 Parent(s): 1c00832

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -43
app.py CHANGED
@@ -1573,7 +1573,8 @@ def verify_phone_number(phone_number):
1573
  else:
1574
  return "Error"
1575
 
1576
-
 
1577
 
1578
 
1579
  def parse_csv_data(data):
@@ -1590,59 +1591,58 @@ def parse_csv_data(data):
1590
 
1591
 
1592
 
 
 
 
1593
  def insert_data(data, verify_phone, add_curator):
1594
  global current_curator_index
1595
- conn = sqlite3.connect(DATABASE2)
1596
- cursor = conn.cursor()
1597
-
1598
- for row in data:
1599
- name = row.get('Name', '')
1600
- phone = row.get('Phone', '').lstrip('+')
1601
- email = row.get('Email', '')
1602
- data_t = row.get('Date', '').strip('"')
1603
 
1604
- cursor.execute("SELECT 1 FROM contacts WHERE email = ? OR phone = ?", (email, phone))
1605
- user_exists = cursor.fetchone()
 
 
 
1606
 
1607
- if user_exists:
1608
- print(f"User with email {email} or phone {phone} already exists. Updating data.")
1609
- else:
1610
- print(f"User with email {email} or phone {phone} does not exist. Inserting new data.")
1611
 
1612
- if add_curator == "1":
1613
- curator = curators[current_curator_index]
1614
- current_curator_index = (current_curator_index + 1) % len(curators)
1615
- else:
1616
- curator = row.get('curator', '')
1617
-
1618
- if verify_phone == "1":
1619
- verification_result = verify_phone_number(phone)
1620
- print(f"Verification result for phone {phone}: {verification_result}") # Вывод результата верификации в консоль
1621
- if verification_result == "True":
1622
- ws_st = 1
1623
- elif verification_result == "False":
1624
- ws_st = 0
1625
  else:
1626
- ws_st = 0 # Или другое значение по умолчанию
1627
- else:
1628
- ws_st = row.get('ws_st', '')
1629
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1630
 
1631
- columns = ['name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog', 'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator', 'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'gc_url', 'key_pr', 'n_con', 'canal', 'data_on', 'data_t', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gcpc']
1632
- values = [name, phone, email, row.get('vk_id', ''), row.get('chat_id', ''), ws_st, row.get('ws_stop', ''), row.get('web_st', 0), row.get('fin_prog', 0), row.get('b_city', ''), row.get('b_fin', ''), row.get('b_ban', ''), row.get('b_ign', ''), row.get('b_baners', ''), row.get('b_butt', ''), row.get('b_mess', ''), row.get('shop_st', ''), curator, row.get('pr1', ''), row.get('pr2', ''), row.get('pr3', ''), row.get('pr4', ''), row.get('pr5', ''), row.get('gc_url', ''), row.get('key_pr', ''), row.get('n_con', ''), row.get('canal', ''), row.get('data_on', ''), row.get('data_t', ''), row.get('utm_source', ''), row.get('utm_medium', ''), row.get('utm_campaign', ''), row.get('utm_term', ''), row.get('utm_content', ''), row.get('gcpc', '')]
1633
 
1634
- placeholders = ', '.join(['?' for _ in columns])
1635
- columns_str = ', '.join(columns)
1636
 
1637
- if user_exists:
1638
- update_query = f"UPDATE contacts SET {', '.join([f'{col} = ?' for col in columns])} WHERE email = ? OR phone = ?"
1639
- cursor.execute(update_query, values + [email, phone])
1640
- else:
1641
- insert_query = f"INSERT INTO contacts ({columns_str}) VALUES ({placeholders})"
1642
- cursor.execute(insert_query, values)
1643
 
1644
- conn.commit()
1645
- conn.close()
1646
 
1647
  @app.route('/upload_csv', methods=['POST'])
1648
  def upload_csv():
 
1573
  else:
1574
  return "Error"
1575
 
1576
+ def clean_phone_number(phone):
1577
+ return ''.join(filter(str.isdigit, phone))
1578
 
1579
 
1580
  def parse_csv_data(data):
 
1591
 
1592
 
1593
 
1594
+ def clean_phone_number(phone):
1595
+ return ''.join(filter(str.isdigit, phone))
1596
+
1597
  def insert_data(data, verify_phone, add_curator):
1598
  global current_curator_index
1599
+ with sqlite3.connect(DATABASE2) as conn:
1600
+ cursor = conn.cursor()
 
 
 
 
 
 
1601
 
1602
+ for row in data:
1603
+ name = row.get('Name', '')
1604
+ phone = clean_phone_number(row.get('Phone', ''))
1605
+ email = row.get('Email', '')
1606
+ data_t = row.get('Date', '').strip('"')
1607
 
1608
+ cursor.execute("SELECT 1 FROM contacts WHERE email = ? OR phone = ?", (email, phone))
1609
+ user_exists = cursor.fetchone()
 
 
1610
 
1611
+ if user_exists:
1612
+ print(f"User with email {email} or phone {phone} already exists. Updating data.")
 
 
 
 
 
 
 
 
 
 
 
1613
  else:
1614
+ print(f"User with email {email} or phone {phone} does not exist. Inserting new data.")
 
 
1615
 
1616
+ if add_curator == "1":
1617
+ curator = curators[current_curator_index]
1618
+ current_curator_index = (current_curator_index + 1) % len(curators)
1619
+ else:
1620
+ curator = row.get('curator', '')
1621
+
1622
+ if verify_phone == "1":
1623
+ verification_result = verify_phone_number(phone)
1624
+ print(f"Verification result for phone {phone}: {verification_result}") # Вывод результата верификации в консоль
1625
+ if verification_result == "True":
1626
+ ws_st = 1
1627
+ else:
1628
+ ws_st = 0
1629
+ else:
1630
+ ws_st = row.get('ws_st', '')
1631
 
1632
+ columns = ['name', 'phone', 'email', 'vk_id', 'chat_id', 'ws_st', 'ws_stop', 'web_st', 'fin_prog', 'b_city', 'b_fin', 'b_ban', 'b_ign', 'b_baners', 'b_butt', 'b_mess', 'shop_st', 'curator', 'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'gc_url', 'key_pr', 'n_con', 'canal', 'data_on', 'data_t', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gcpc']
1633
+ values = [name, phone, email, row.get('vk_id', ''), row.get('chat_id', ''), ws_st, row.get('ws_stop', ''), row.get('web_st', 0), row.get('fin_prog', 0), row.get('b_city', ''), row.get('b_fin', ''), row.get('b_ban', ''), row.get('b_ign', ''), row.get('b_baners', ''), row.get('b_butt', ''), row.get('b_mess', ''), row.get('shop_st', ''), curator, row.get('pr1', ''), row.get('pr2', ''), row.get('pr3', ''), row.get('pr4', ''), row.get('pr5', ''), row.get('gc_url', ''), row.get('key_pr', ''), row.get('n_con', ''), row.get('canal', ''), row.get('data_on', ''), row.get('data_t', ''), row.get('utm_source', ''), row.get('utm_medium', ''), row.get('utm_campaign', ''), row.get('utm_term', ''), row.get('utm_content', ''), row.get('gcpc', '')]
1634
 
1635
+ placeholders = ', '.join(['?' for _ in columns])
1636
+ columns_str = ', '.join(columns)
1637
 
1638
+ if user_exists:
1639
+ update_query = f"UPDATE contacts SET {', '.join([f'{col} = ?' for col in columns])} WHERE email = ? OR phone = ?"
1640
+ cursor.execute(update_query, values + [email, phone])
1641
+ else:
1642
+ insert_query = f"INSERT INTO contacts ({columns_str}) VALUES ({placeholders})"
1643
+ cursor.execute(insert_query, values)
1644
 
1645
+ conn.commit()
 
1646
 
1647
  @app.route('/upload_csv', methods=['POST'])
1648
  def upload_csv():