from flask import Blueprint, request, jsonify import sqlite3 # from services.rokky import ones # from API.rok import get_order_content import logging main = Blueprint("main", __name__) DB_PATH = "./files/rokky.db" @main.route("/") def index(): return "Hello wstkeys!!!" @main.route("/orders/api_payments", methods=["POST", "GET"]) def index1(): # Получаем все GET-параметры params = request.args.to_dict() logging.warn(f"newOrder: {params}") # Просто выводим на экран (в ответ клиенту) return f"Received params: {params}", 200 return "Hello GET" @main.route("/sales", methods=["POST", "GET"]) def index2(): return "Hello GET!!!++!!ss" @main.route("/newOrder", methods=["POST"]) def new_order(): if not request.is_json: return jsonify({"error": "Invalid content type"}), 400 data = request.get_json() print(data) order_id = data.get("orderId") if order_id is None: return jsonify({"error": "orderId is required"}), 400 if not isinstance(order_id, int): return jsonify({"error": "orderId must be int"}), 400 # TODO: обработка заказа print(f"New order received: {order_id}") # logging.warn(get_order_content(order_id)) logging.warn(f"newOrder: {order_id}") return jsonify({"status": "ok"}), 200 @main.route("/sku", methods=["POST"]) def sku(): if not request.is_json: return jsonify({"error": "Invalid content type"}), 400 data = request.get_json() print(data) order_id = data.get("orderId") if order_id is None: return jsonify({"error": "orderId is required"}), 400 if not isinstance(order_id, int): return jsonify({"error": "orderId must be int"}), 400 # TODO: обработка заказа print(f"New order received: {order_id}") # logging.warn(get_order_content(order_id)) logging.warn(f"NEWsku: {order_id}") return jsonify({"status": "ok"}), 200 @main.route("/product") def product_update(): # получаем параметры sku = request.args.get("rokky") ggsale = request.args.get("ggsale") if not sku or not ggsale: return jsonify({"error": "Missing parameters"}), 400 conn = sqlite3.connect(DB_PATH) cursor = conn.cursor() # проверяем есть ли продукт с таким SKU cursor.execute("SELECT id FROM products WHERE sku=?", (sku,)) row = cursor.fetchone() if not row: conn.close() return jsonify({"error": "SKU not found"}), 404 # обновляем поле gg cursor.execute("UPDATE products SET gg=? WHERE sku=?", (ggsale, sku)) conn.commit() conn.close() return jsonify({"success": True, "sku": sku, "ggsale": ggsale})