DmitrMakeev
commited on
Commit
•
209661f
1
Parent(s):
c755187
Update app.py
Browse files
app.py
CHANGED
@@ -1818,13 +1818,14 @@ def insert_data_ss(data):
|
|
1818 |
conn.commit()
|
1819 |
conn.close()
|
1820 |
|
|
|
1821 |
@app.route('/order', methods=['GET'])
|
1822 |
def from_shop_st():
|
1823 |
try:
|
1824 |
api_sys_control = request.args.get('api_sys')
|
1825 |
|
1826 |
if api_sys_control != api_key_sys:
|
1827 |
-
return
|
1828 |
|
1829 |
name = request.args.get('name', '')
|
1830 |
email = request.args.get('email', '')
|
@@ -1834,73 +1835,42 @@ def from_shop_st():
|
|
1834 |
del_flag = request.args.get('del', '')
|
1835 |
|
1836 |
if not email or not phone:
|
1837 |
-
return
|
1838 |
|
|
|
1839 |
phone = clean_phone_number_ss(phone)
|
1840 |
|
1841 |
conn = sqlite3.connect(DATABASE6)
|
1842 |
cursor = conn.cursor()
|
1843 |
|
1844 |
-
cursor.execute("SELECT
|
1845 |
result = cursor.fetchone()
|
1846 |
|
1847 |
if result:
|
1848 |
-
|
1849 |
-
shop_st_index = columns.index('shop_st')
|
1850 |
-
shop_st = result[shop_st_index] if result[shop_st_index] else '{}'
|
1851 |
shop_st_data = json.loads(shop_st)
|
1852 |
else:
|
1853 |
shop_st_data = {}
|
1854 |
|
1855 |
if del_flag == '1':
|
1856 |
-
|
1857 |
-
del shop_st_data[order]
|
1858 |
-
else:
|
1859 |
-
return jsonify({"error": f"Order {order} not found"}), 404
|
1860 |
elif order and status:
|
1861 |
shop_st_data[order] = status
|
1862 |
-
elif not order:
|
1863 |
-
return jsonify({"error": "Order is required"}), 400
|
1864 |
|
1865 |
shop_st_json = json.dumps(shop_st_data)
|
1866 |
|
1867 |
-
excluded_columns = ['b_ban', 'b_baners', 'b_butt', 'b_city', 'b_fin', 'b_ign', 'b_mess', 'canal', 'chat_id', 'curator', 'data_on', 'data_t', 'fin_prog', 'gc_url', 'gcpc', 'key_pr', 'n_con', 'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'utm_campaign', 'utm_content', 'utm_medium', 'utm_source', 'utm_term', 'vk_id', 'web_st', 'ws_st', 'ws_stop']
|
1868 |
-
update_values = [name, phone, email, shop_st_json]
|
1869 |
-
update_columns = ['name', 'phone', 'email', 'shop_st']
|
1870 |
-
|
1871 |
-
for col in columns:
|
1872 |
-
if col not in excluded_columns and col not in update_columns:
|
1873 |
-
value = request.args.get(col, None)
|
1874 |
-
if value is not None:
|
1875 |
-
update_values.append(value)
|
1876 |
-
update_columns.append(col)
|
1877 |
-
|
1878 |
-
placeholders = ', '.join([f"{col} = ?" for col in update_columns])
|
1879 |
-
query = f"UPDATE contacts SET {placeholders} WHERE email = ? OR phone = ?"
|
1880 |
-
update_values.extend([email, phone])
|
1881 |
-
|
1882 |
if result:
|
1883 |
-
cursor.execute(
|
1884 |
else:
|
1885 |
-
|
1886 |
-
insert_values = [name, phone, email, shop_st_json]
|
1887 |
-
for col in columns:
|
1888 |
-
if col not in excluded_columns and col not in insert_columns:
|
1889 |
-
value = request.args.get(col, None)
|
1890 |
-
if value is not None:
|
1891 |
-
insert_values.append(value)
|
1892 |
-
insert_columns.append(col)
|
1893 |
-
insert_placeholders = ', '.join(['?' for _ in insert_columns])
|
1894 |
-
insert_query = f"INSERT INTO contacts ({', '.join(insert_columns)}) VALUES ({insert_placeholders})"
|
1895 |
-
cursor.execute(insert_query, insert_values)
|
1896 |
|
1897 |
conn.commit()
|
1898 |
conn.close()
|
1899 |
|
1900 |
-
return
|
1901 |
|
1902 |
except Exception as e:
|
1903 |
-
return
|
1904 |
|
1905 |
|
1906 |
|
|
|
1818 |
conn.commit()
|
1819 |
conn.close()
|
1820 |
|
1821 |
+
# Маршрут для приема GET запроса
|
1822 |
@app.route('/order', methods=['GET'])
|
1823 |
def from_shop_st():
|
1824 |
try:
|
1825 |
api_sys_control = request.args.get('api_sys')
|
1826 |
|
1827 |
if api_sys_control != api_key_sys:
|
1828 |
+
return json.dumps({"error": "Unauthorized access"}), 403
|
1829 |
|
1830 |
name = request.args.get('name', '')
|
1831 |
email = request.args.get('email', '')
|
|
|
1835 |
del_flag = request.args.get('del', '')
|
1836 |
|
1837 |
if not email or not phone:
|
1838 |
+
return json.dumps({"error": "Email and phone are required"}), 400
|
1839 |
|
1840 |
+
# Очистка номера телефона
|
1841 |
phone = clean_phone_number_ss(phone)
|
1842 |
|
1843 |
conn = sqlite3.connect(DATABASE6)
|
1844 |
cursor = conn.cursor()
|
1845 |
|
1846 |
+
cursor.execute("SELECT shop_st FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
1847 |
result = cursor.fetchone()
|
1848 |
|
1849 |
if result:
|
1850 |
+
shop_st = result[0] if result[0] else '{}'
|
|
|
|
|
1851 |
shop_st_data = json.loads(shop_st)
|
1852 |
else:
|
1853 |
shop_st_data = {}
|
1854 |
|
1855 |
if del_flag == '1':
|
1856 |
+
shop_st_data = {}
|
|
|
|
|
|
|
1857 |
elif order and status:
|
1858 |
shop_st_data[order] = status
|
|
|
|
|
1859 |
|
1860 |
shop_st_json = json.dumps(shop_st_data)
|
1861 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1862 |
if result:
|
1863 |
+
cursor.execute("UPDATE contacts SET name = ?, phone = ?, email = ?, shop_st = ? WHERE email = ? OR phone = ?", (name, phone, email, shop_st_json, email, phone))
|
1864 |
else:
|
1865 |
+
cursor.execute("INSERT INTO contacts (name, phone, email, shop_st) VALUES (?, ?, ?, ?)", (name, phone, email, shop_st_json))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1866 |
|
1867 |
conn.commit()
|
1868 |
conn.close()
|
1869 |
|
1870 |
+
return json.dumps(shop_st_data), 200
|
1871 |
|
1872 |
except Exception as e:
|
1873 |
+
return json.dumps({"error": str(e)}), 500
|
1874 |
|
1875 |
|
1876 |
|