DmitrMakeev commited on
Commit
0c591a4
·
verified ·
1 Parent(s): 04fd444

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -20
app.py CHANGED
@@ -781,28 +781,26 @@ def set_order_vk():
781
  cursor.execute("SELECT orders FROM contacts WHERE vk_id = ?", (vkid,))
782
  result = cursor.fetchone()
783
 
784
- if result:
785
- shop_st = result[0] if result[0] else '{}'
786
- shop_st_data = json.loads(shop_st)
787
- logging.debug(f"Existing record found. Loaded JSON: {shop_st_data}")
 
788
 
789
- # Ищем значение по ключу order
790
- value = shop_st_data.get(order, None)
791
- if value:
792
- # Получаем текущую дату и время на сервере
793
- utc_now = datetime.utcnow()
794
- msk_tz = pytz.timezone('Europe/Moscow')
795
- msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
796
- current_time = msk_now.isoformat(timespec='microseconds')
797
-
798
- # Возвращаем данные из столбца и текущую дату и время
799
- return jsonify({order: value, 'online_date': current_time}), 200
800
- else:
801
- logging.error(f"Order {order} not found")
802
- return json.dumps({"error": f"Order not found"}), 404
803
- else:
804
  logging.error(f"VK ID {vkid} not found")
805
- return json.dumps({"error": f"VK ID not found"}), 404
 
 
 
 
 
 
 
 
 
 
806
 
807
  except Exception as e:
808
  logging.error(f"An error occurred: {str(e)}")
 
781
  cursor.execute("SELECT orders FROM contacts WHERE vk_id = ?", (vkid,))
782
  result = cursor.fetchone()
783
 
784
+ # Получаем текущую дату и время на сервере
785
+ utc_now = datetime.utcnow()
786
+ msk_tz = pytz.timezone('Europe/Moscow')
787
+ msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
788
+ current_time = msk_now.isoformat(timespec='microseconds')
789
 
790
+ # Если запись по vk_id не найдена, возвращаем значение "not" для ордера
791
+ if not result:
 
 
 
 
 
 
 
 
 
 
 
 
 
792
  logging.error(f"VK ID {vkid} not found")
793
+ return jsonify({order: 'not', 'online_date': current_time}), 200
794
+
795
+ shop_st = result[0] if result[0] else '{}'
796
+ shop_st_data = json.loads(shop_st)
797
+ logging.debug(f"Existing record found. Loaded JSON: {shop_st_data}")
798
+
799
+ # Ищем значение по ключу order
800
+ value = shop_st_data.get(order, 'not')
801
+
802
+ # Возвращаем данные из столбца и текущую дату и время
803
+ return jsonify({order: value, 'online_date': current_time}), 200
804
 
805
  except Exception as e:
806
  logging.error(f"An error occurred: {str(e)}")