DmitrMakeev commited on
Commit
7e280e2
1 Parent(s): 9dbd12a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -152
app.py CHANGED
@@ -1775,155 +1775,6 @@ DATABASE6 = 'data_gc.db'
1775
  def clean_phone_number_ss(phone_number):
1776
  return re.sub(r'\D', '', phone_number)
1777
 
1778
- # Маршрут для приема GET запроса
1779
- @app.route('/order', methods=['GET'])
1780
- def from_shop_st():
1781
- try:
1782
- api_sys_control = request.args.get('api_sys')
1783
-
1784
- if api_sys_control != api_key_sys:
1785
- return json.dumps({"error": "Unauthorized access"}), 403
1786
-
1787
- name = request.args.get('name', '')
1788
- email = request.args.get('email', '')
1789
- phone = request.args.get('phone', '').lstrip('+')
1790
- order = request.args.get('order', '')
1791
- status = request.args.get('status', '')
1792
- del_flag = request.args.get('del', '')
1793
- n_con_flag = request.args.get('n_con', '') # Добавь прием этого параметра и запись его в столбец базы данных 'n_con'
1794
-
1795
- if not email or not phone:
1796
- return json.dumps({"error": "Email and phone are required"}), 400
1797
-
1798
- # Очистка номера телефона
1799
- phone = clean_phone_number_ss(phone)
1800
-
1801
- conn = sqlite3.connect(DATABASE6)
1802
- cursor = conn.cursor()
1803
-
1804
- cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
1805
- result = cursor.fetchone()
1806
-
1807
- if result:
1808
- shop_st = result[17] if result[17] else '{}'
1809
- shop_st_data = json.loads(shop_st)
1810
- else:
1811
- shop_st_data = {}
1812
-
1813
- if del_flag == '1':
1814
- shop_st_data = {}
1815
- elif order and status:
1816
- shop_st_data[order] = status
1817
-
1818
- shop_st_json = json.dumps(shop_st_data)
1819
-
1820
- if result:
1821
- # Создаем словарь текущих данных
1822
- current_data = {
1823
- 'name': result[1],
1824
- 'phone': result[2],
1825
- 'email': result[3],
1826
- 'shop_st': shop_st_json
1827
- }
1828
-
1829
- # Обновляем только те поля, которые переданы в запросе
1830
- if name:
1831
- current_data['name'] = name
1832
- if phone:
1833
- current_data['phone'] = phone
1834
- if email:
1835
- current_data['email'] = email
1836
-
1837
- cursor.execute("""
1838
- UPDATE contacts
1839
- SET name = ?, phone = ?, email = ?, shop_st = ?
1840
- WHERE email = ? OR phone = ?
1841
- """, (current_data['name'], current_data['phone'], current_data['email'], current_data['shop_st'], email, phone))
1842
- else:
1843
- cursor.execute("""
1844
- INSERT INTO contacts (name, phone, email, shop_st)
1845
- VALUES (?, ?, ?, ?)
1846
- """, (name, phone, email, shop_st_json))
1847
-
1848
- conn.commit()
1849
- conn.close()
1850
-
1851
- return json.dumps(shop_st_data), 200
1852
-
1853
- except Exception as e:
1854
- return json.dumps({"error": str(e)}), 500
1855
-
1856
-
1857
-
1858
-
1859
-
1860
-
1861
-
1862
-
1863
- # Маршрут для приема GET запроса
1864
- @app.route('/order2', methods=['GET'])
1865
- def from_shop_st2():
1866
- try:
1867
- api_sys_control = request.args.get('api_sys')
1868
-
1869
- if api_sys_control != api_key_sys:
1870
- return json.dumps({"error": "Unauthorized access"}), 403
1871
-
1872
- name = request.args.get('name', '')
1873
- email = request.args.get('email', '')
1874
- phone = request.args.get('phone', '').lstrip('+')
1875
- order = request.args.get('order', '')
1876
- status = request.args.get('status', '')
1877
- del_flag = request.args.get('del', '')
1878
- n_con_flag = request.args.get('n_con', '') # Добавлен параметр n_con
1879
-
1880
- if not email or not phone:
1881
- return json.dumps({"error": "Email and phone are required"}), 400
1882
-
1883
- # Очистка номера телефона
1884
- phone = clean_phone_number_ss(phone)
1885
-
1886
- conn = sqlite3.connect(DATABASE6)
1887
- cursor = conn.cursor()
1888
-
1889
- cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
1890
- result = cursor.fetchone()
1891
-
1892
- if result:
1893
- shop_st = result[17] if result[17] else '{}'
1894
- shop_st_data = json.loads(shop_st)
1895
- else:
1896
- shop_st_data = {}
1897
-
1898
- if del_flag == '1':
1899
- shop_st_data = {}
1900
- elif order and status:
1901
- shop_st_data[order] = status
1902
-
1903
- shop_st_json = json.dumps(shop_st_data)
1904
-
1905
- # Исключаем все столбцы, кроме name, phone, email, shop_st, n_con
1906
- columns_to_update = ['name', 'phone', 'email', 'shop_st', 'n_con']
1907
- values_to_update = [name, phone, email, shop_st_json, n_con_flag]
1908
-
1909
- if result:
1910
- # Обновляем только те поля, которые переданы в запросе
1911
- set_clause = ', '.join([f"{col} = ?" for col in columns_to_update])
1912
- query = f"UPDATE contacts SET {set_clause} WHERE email = ? OR phone = ?"
1913
- cursor.execute(query, values_to_update + [email, phone])
1914
- else:
1915
- # Вставляем новые данные
1916
- query = f"INSERT INTO contacts ({', '.join(columns_to_update)}) VALUES ({', '.join(['?' for _ in columns_to_update])})"
1917
- cursor.execute(query, values_to_update)
1918
-
1919
- conn.commit()
1920
- conn.close()
1921
-
1922
- return json.dumps(shop_st_data), 200
1923
-
1924
- except Exception as e:
1925
- return json.dumps({"error": str(e)}), 500
1926
-
1927
 
1928
 
1929
 
@@ -1970,9 +1821,15 @@ def from_shop_st3():
1970
 
1971
  shop_st_json = json.dumps(shop_st_data)
1972
 
1973
- # Исключаем все столбцы, кроме name, phone, email, shop_st, n_con
1974
- columns_to_update = ['name', 'phone', 'email', 'shop_st', 'n_con']
1975
- values_to_update = [name, phone, email, shop_st_json, n_con_flag]
 
 
 
 
 
 
1976
 
1977
  if result:
1978
  # Обновляем только те поля, которые переданы в запросе
@@ -2027,6 +1884,7 @@ def from_shop_st3():
2027
 
2028
 
2029
 
 
2030
 
2031
 
2032
  @app.route('/gc_in', methods=['GET'])
 
1775
  def clean_phone_number_ss(phone_number):
1776
  return re.sub(r'\D', '', phone_number)
1777
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1778
 
1779
 
1780
 
 
1821
 
1822
  shop_st_json = json.dumps(shop_st_data)
1823
 
1824
+ # Получение текущей даты и времени в Московском часовом поясе
1825
+ utc_now = datetime.utcnow()
1826
+ msk_tz = pytz.timezone('Europe/Moscow')
1827
+ msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
1828
+ data_on = msk_now.strftime('%Y-%m-%d %H:%M:%S')
1829
+
1830
+ # Исключаем все столбцы, кроме name, phone, email, shop_st, n_con, data_on
1831
+ columns_to_update = ['name', 'phone', 'email', 'shop_st', 'n_con', 'data_on']
1832
+ values_to_update = [name, phone, email, shop_st_json, n_con_flag, data_on]
1833
 
1834
  if result:
1835
  # Обновляем только те поля, которые переданы в запросе
 
1884
 
1885
 
1886
 
1887
+
1888
 
1889
 
1890
  @app.route('/gc_in', methods=['GET'])