Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -622,6 +622,14 @@ def shop_order_new():
|
|
622 |
|
623 |
|
624 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
625 |
# Данные формы из ВК
|
626 |
@app.route('/wr_form_vk', methods=['POST'])
|
627 |
def wr_form_vk():
|
@@ -676,22 +684,9 @@ def wr_form_vk():
|
|
676 |
return json.dumps({"error": str(e)}), 500
|
677 |
|
678 |
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
# Работа из VK_ID только по VK ID
|
693 |
-
@app.route('/wr_order_vk', methods=['POST'])
|
694 |
-
def wr_order_vk():
|
695 |
try:
|
696 |
logging.debug("Starting wr_order_vk")
|
697 |
|
@@ -760,6 +755,60 @@ def wr_order_vk():
|
|
760 |
logging.error(f"An error occurred: {str(e)}")
|
761 |
return json.dumps({"error": str(e)}), 500
|
762 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
763 |
|
764 |
|
765 |
|
|
|
622 |
|
623 |
|
624 |
|
625 |
+
|
626 |
+
|
627 |
+
|
628 |
+
|
629 |
+
|
630 |
+
|
631 |
+
|
632 |
+
|
633 |
# Данные формы из ВК
|
634 |
@app.route('/wr_form_vk', methods=['POST'])
|
635 |
def wr_form_vk():
|
|
|
684 |
return json.dumps({"error": str(e)}), 500
|
685 |
|
686 |
|
687 |
+
# Запись ордера по ключу и ВК ИД
|
688 |
+
@app.route('/set_order_vk', methods=['POST'])
|
689 |
+
def get_order_vk():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
690 |
try:
|
691 |
logging.debug("Starting wr_order_vk")
|
692 |
|
|
|
755 |
logging.error(f"An error occurred: {str(e)}")
|
756 |
return json.dumps({"error": str(e)}), 500
|
757 |
|
758 |
+
# Чтение ордера по ключу и ВК ИД
|
759 |
+
@app.route('/get_order_vk', methods=['GET'])
|
760 |
+
def set_order_vk():
|
761 |
+
try:
|
762 |
+
logging.debug("Starting set_order_vk")
|
763 |
+
|
764 |
+
# Читаем параметры из GET-запроса
|
765 |
+
api_sys_control = request.args.get('api_sys')
|
766 |
+
if api_sys_control != api_key_sys:
|
767 |
+
logging.warning("Unauthorized access attempt")
|
768 |
+
return json.dumps({"error": "Unauthorized access"}), 403
|
769 |
+
|
770 |
+
vkid = request.args.get('vk_id', '')
|
771 |
+
order = request.args.get('order', '')
|
772 |
+
|
773 |
+
if not vkid or not order:
|
774 |
+
logging.error("VK ID and order are required")
|
775 |
+
return json.dumps({"error": "VK ID and order are required"}), 400
|
776 |
+
|
777 |
+
conn = sqlite3.connect(DATABASE_NEW)
|
778 |
+
cursor = conn.cursor()
|
779 |
+
|
780 |
+
# Ищем запись по vk_id
|
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 |
+
return jsonify({order: value}), 200
|
793 |
+
else:
|
794 |
+
logging.error(f"Order {order} not found")
|
795 |
+
return json.dumps({"error": f"Order {order} not found"}), 404
|
796 |
+
else:
|
797 |
+
logging.error(f"VK ID {vkid} not found")
|
798 |
+
return json.dumps({"error": f"VK ID {vkid} not found"}), 404
|
799 |
+
|
800 |
+
except Exception as e:
|
801 |
+
logging.error(f"An error occurred: {str(e)}")
|
802 |
+
return json.dumps({"error": str(e)}), 500
|
803 |
+
|
804 |
+
|
805 |
+
|
806 |
+
|
807 |
+
|
808 |
+
|
809 |
+
|
810 |
+
|
811 |
+
|
812 |
|
813 |
|
814 |
|