DmitrMakeev
commited on
Commit
•
71751e3
1
Parent(s):
87d67c6
Update app.py
Browse files
app.py
CHANGED
@@ -1773,6 +1773,7 @@ DATABASE6 = 'data_gc.db'
|
|
1773 |
def clean_phone_number_ss(phone_number):
|
1774 |
return re.sub(r'\D', '', phone_number)
|
1775 |
|
|
|
1776 |
@app.route('/order', methods=['GET'])
|
1777 |
def from_shop_st():
|
1778 |
try:
|
@@ -1797,11 +1798,11 @@ def from_shop_st():
|
|
1797 |
conn = sqlite3.connect(DATABASE6)
|
1798 |
cursor = conn.cursor()
|
1799 |
|
1800 |
-
cursor.execute("SELECT
|
1801 |
result = cursor.fetchone()
|
1802 |
|
1803 |
if result:
|
1804 |
-
shop_st = result[
|
1805 |
shop_st_data = json.loads(shop_st)
|
1806 |
else:
|
1807 |
shop_st_data = {}
|
@@ -1814,20 +1815,27 @@ def from_shop_st():
|
|
1814 |
shop_st_json = json.dumps(shop_st_data)
|
1815 |
|
1816 |
if result:
|
1817 |
-
#
|
1818 |
-
|
1819 |
-
|
|
|
|
|
|
|
|
|
1820 |
|
1821 |
-
#
|
1822 |
-
|
1823 |
-
|
1824 |
-
|
|
|
|
|
|
|
1825 |
|
1826 |
cursor.execute("""
|
1827 |
UPDATE contacts
|
1828 |
SET name = ?, phone = ?, email = ?, shop_st = ?
|
1829 |
WHERE email = ? OR phone = ?
|
1830 |
-
""", (name, phone, email,
|
1831 |
else:
|
1832 |
cursor.execute("""
|
1833 |
INSERT INTO contacts (name, phone, email, shop_st)
|
@@ -1886,8 +1894,6 @@ def from_shop_st():
|
|
1886 |
|
1887 |
|
1888 |
|
1889 |
-
|
1890 |
-
|
1891 |
|
1892 |
|
1893 |
|
|
|
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():
|
1779 |
try:
|
|
|
1798 |
conn = sqlite3.connect(DATABASE6)
|
1799 |
cursor = conn.cursor()
|
1800 |
|
1801 |
+
cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
|
1802 |
result = cursor.fetchone()
|
1803 |
|
1804 |
if result:
|
1805 |
+
shop_st = result[17] if result[17] else '{}'
|
1806 |
shop_st_data = json.loads(shop_st)
|
1807 |
else:
|
1808 |
shop_st_data = {}
|
|
|
1815 |
shop_st_json = json.dumps(shop_st_data)
|
1816 |
|
1817 |
if result:
|
1818 |
+
# Создаем словарь текущих данных
|
1819 |
+
current_data = {
|
1820 |
+
'name': result[1],
|
1821 |
+
'phone': result[2],
|
1822 |
+
'email': result[3],
|
1823 |
+
'shop_st': shop_st_json
|
1824 |
+
}
|
1825 |
|
1826 |
+
# Обновляем только те поля, которые переданы в запросе
|
1827 |
+
if name:
|
1828 |
+
current_data['name'] = name
|
1829 |
+
if phone:
|
1830 |
+
current_data['phone'] = phone
|
1831 |
+
if email:
|
1832 |
+
current_data['email'] = email
|
1833 |
|
1834 |
cursor.execute("""
|
1835 |
UPDATE contacts
|
1836 |
SET name = ?, phone = ?, email = ?, shop_st = ?
|
1837 |
WHERE email = ? OR phone = ?
|
1838 |
+
""", (current_data['name'], current_data['phone'], current_data['email'], current_data['shop_st'], email, phone))
|
1839 |
else:
|
1840 |
cursor.execute("""
|
1841 |
INSERT INTO contacts (name, phone, email, shop_st)
|
|
|
1894 |
|
1895 |
|
1896 |
|
|
|
|
|
1897 |
|
1898 |
|
1899 |
|