DmitrMakeev commited on
Commit
ac27597
1 Parent(s): 209661f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -1843,13 +1843,15 @@ def from_shop_st():
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':
@@ -1860,9 +1862,16 @@ def from_shop_st():
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()
 
1843
  conn = sqlite3.connect(DATABASE6)
1844
  cursor = conn.cursor()
1845
 
1846
+ cursor.execute("SELECT name, phone, email, shop_st FROM contacts WHERE email = ? OR phone = ?", (email, phone))
1847
  result = cursor.fetchone()
1848
 
1849
  if result:
1850
+ name_db, phone_db, email_db, shop_st = result
1851
+ shop_st = shop_st if shop_st else '{}'
1852
  shop_st_data = json.loads(shop_st)
1853
  else:
1854
+ name_db, phone_db, email_db = name, phone, email
1855
  shop_st_data = {}
1856
 
1857
  if del_flag == '1':
 
1862
  shop_st_json = json.dumps(shop_st_data)
1863
 
1864
  if result:
1865
+ cursor.execute("""
1866
+ UPDATE contacts
1867
+ SET name = ?, phone = ?, email = ?, shop_st = ?
1868
+ WHERE email = ? OR phone = ?""",
1869
+ (name or name_db, phone or phone_db, email or email_db, shop_st_json, email, phone))
1870
  else:
1871
+ cursor.execute("""
1872
+ INSERT INTO contacts (name, phone, email, shop_st)
1873
+ VALUES (?, ?, ?, ?)""",
1874
+ (name_db, phone_db, email_db, shop_st_json))
1875
 
1876
  conn.commit()
1877
  conn.close()