DmitrMakeev
commited on
Commit
•
c4b2049
1
Parent(s):
4c58695
Update app.py
Browse files
app.py
CHANGED
@@ -1768,56 +1768,11 @@ def display_form():
|
|
1768 |
DATABASE6 = 'data_gc.db'
|
1769 |
|
1770 |
|
|
|
1771 |
# Функция для очистки номера телефона
|
1772 |
def clean_phone_number_ss(phone_number):
|
1773 |
return re.sub(r'\D', '', phone_number)
|
1774 |
|
1775 |
-
# Функция для вставки данных в базу данных
|
1776 |
-
def insert_data_ss(data):
|
1777 |
-
conn = sqlite3.connect(DATABASE6)
|
1778 |
-
cursor = conn.cursor()
|
1779 |
-
|
1780 |
-
for row in data:
|
1781 |
-
name = row.get('name', '')
|
1782 |
-
phone = row.get('phone', '').lstrip('+')
|
1783 |
-
email = row.get('email', '')
|
1784 |
-
data_t = row.get('data_t', '').strip('"')
|
1785 |
-
|
1786 |
-
phone = clean_phone_number_ss(phone)
|
1787 |
-
|
1788 |
-
cursor.execute("SELECT 1 FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
1789 |
-
user_exists = cursor.fetchone()
|
1790 |
-
|
1791 |
-
if user_exists:
|
1792 |
-
print(f"User with email {email} or phone {phone} already exists. Skipping insert.")
|
1793 |
-
continue
|
1794 |
-
|
1795 |
-
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']
|
1796 |
-
values = [name, phone, email, row.get('vk_id', ''), row.get('chat_id', ''), row.get('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', ''), row.get('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', '')]
|
1797 |
-
|
1798 |
-
excluded_columns = ['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']
|
1799 |
-
columns = [col for col in columns if col not in excluded_columns]
|
1800 |
-
values = [values[columns.index(col)] for col in columns]
|
1801 |
-
|
1802 |
-
placeholders = ', '.join(['?' for _ in columns])
|
1803 |
-
columns_str = ', '.join(columns)
|
1804 |
-
|
1805 |
-
query = f'''
|
1806 |
-
INSERT INTO contacts ({columns_str})
|
1807 |
-
VALUES ({placeholders})
|
1808 |
-
'''
|
1809 |
-
|
1810 |
-
try:
|
1811 |
-
cursor.execute(query, values)
|
1812 |
-
except Exception as e:
|
1813 |
-
print(f"Error inserting row: {row}")
|
1814 |
-
print(f"Error message: {str(e)}")
|
1815 |
-
conn.rollback()
|
1816 |
-
continue
|
1817 |
-
|
1818 |
-
conn.commit()
|
1819 |
-
conn.close()
|
1820 |
-
|
1821 |
# Маршрут для приема GET запроса
|
1822 |
@app.route('/order', methods=['GET'])
|
1823 |
def from_shop_st():
|
@@ -1947,6 +1902,7 @@ def from_shop_st():
|
|
1947 |
|
1948 |
|
1949 |
|
|
|
1950 |
|
1951 |
|
1952 |
@app.route('/gc_in', methods=['GET'])
|
|
|
1768 |
DATABASE6 = 'data_gc.db'
|
1769 |
|
1770 |
|
1771 |
+
# Функция для очистки номера телефона
|
1772 |
# Функция для очистки номера телефона
|
1773 |
def clean_phone_number_ss(phone_number):
|
1774 |
return re.sub(r'\D', '', phone_number)
|
1775 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1776 |
# Маршрут для приема GET запроса
|
1777 |
@app.route('/order', methods=['GET'])
|
1778 |
def from_shop_st():
|
|
|
1902 |
|
1903 |
|
1904 |
|
1905 |
+
|
1906 |
|
1907 |
|
1908 |
@app.route('/gc_in', methods=['GET'])
|