Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -811,7 +811,66 @@ def get_order_vk():
|
|
811 |
logging.error(f"An error occurred: {str(e)}")
|
812 |
return json.dumps({"error": str(e)}), 500
|
813 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
814 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
815 |
|
816 |
|
817 |
|
|
|
811 |
logging.error(f"An error occurred: {str(e)}")
|
812 |
return json.dumps({"error": str(e)}), 500
|
813 |
|
814 |
+
|
815 |
+
# Чтение ордера по ключу и ВК ИД для Автопилота
|
816 |
+
@app.route('/get_order', methods=['GET'])
|
817 |
+
def get_order():
|
818 |
+
try:
|
819 |
+
logging.debug("Starting set_order")
|
820 |
+
|
821 |
+
# Читаем параметры из GET-запроса
|
822 |
+
api_sys_control = request.args.get('api_sys')
|
823 |
+
if api_sys_control != api_key_sys:
|
824 |
+
logging.warning("Unauthorized access attempt")
|
825 |
+
return json.dumps({"error": "Unauthorized access"}), 403
|
826 |
+
|
827 |
+
vkid = request.args.get('vk_id', '')
|
828 |
+
order = request.args.get('order', '')
|
829 |
+
|
830 |
+
if not vkid or not order:
|
831 |
+
logging.error("VK ID and order are required")
|
832 |
+
return json.dumps({"error": "VK ID and order are required"}), 400
|
833 |
+
|
834 |
+
conn = sqlite3.connect(DATABASE_NEW)
|
835 |
+
cursor = conn.cursor()
|
836 |
+
|
837 |
+
# Ищем запись по vk_id
|
838 |
+
cursor.execute("SELECT orders FROM contacts WHERE vk_id = ?", (vkid,))
|
839 |
+
result = cursor.fetchone()
|
840 |
+
|
841 |
+
# Получаем текущую дату и время на сервере
|
842 |
+
utc_now = datetime.utcnow()
|
843 |
+
msk_tz = pytz.timezone('Europe/Moscow')
|
844 |
+
msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
|
845 |
+
current_time = msk_now.isoformat(timespec='microseconds')
|
846 |
|
847 |
+
# Если запись по vk_id не найдена, возвращаем значение "not" для ордера
|
848 |
+
if not result:
|
849 |
+
logging.error(f"VK ID {vkid} not found")
|
850 |
+
response = {order: 'not', 'online_date': current_time, 'crypto': ''}
|
851 |
+
return jsonify(response), 200
|
852 |
+
|
853 |
+
shop_st = result[0] if result[0] else '{}'
|
854 |
+
shop_st_data = json.loads(shop_st)
|
855 |
+
logging.debug(f"Existing record found. Loaded JSON: {shop_st_data}")
|
856 |
+
|
857 |
+
# Ищем значение по ключу order
|
858 |
+
value = shop_st_data.get(order, 'not')
|
859 |
+
|
860 |
+
# Определяем значение для crypto
|
861 |
+
crypto_value = crypto_key_sys if value != 'not' else ''
|
862 |
+
|
863 |
+
# Возвращаем данные из столбца и текущую дату и время
|
864 |
+
response = {order: value, 'online_date': current_time, 'crypto': crypto_value}
|
865 |
+
return jsonify(response), 200
|
866 |
+
|
867 |
+
except Exception as e:
|
868 |
+
logging.error(f"An error occurred: {str(e)}")
|
869 |
+
return json.dumps({"error": str(e)}), 500
|
870 |
+
|
871 |
+
|
872 |
+
|
873 |
+
|
874 |
|
875 |
|
876 |
|