This commit is contained in:
Alex55 2026-03-19 19:03:33 +02:00
parent 6f7bd73520
commit 7c028e5069
3 changed files with 53 additions and 10 deletions

View File

@ -165,17 +165,35 @@ def add_product():
def update_prices(): def update_prices():
with open("./files/prices.json", "r") as f: with open("./files/prices.json", "r") as f:
prices = json.load(f) prices = json.load(f)
cursor = conn.cursor() cursor = conn.cursor()
data = [(item["price"], item["sku"]) for item in prices] data = []
for item in prices:
sku = item["sku"]
price = item.get("basePrice")
price_gg = item.get("baseSuggestedRetailPrice")
price_sales =item.get("discountPercentage")
is_sale = item.get("isSale")
data.append((
price,
price_gg,
price_sales,
is_sale,
sku
))
cursor.executemany(""" cursor.executemany("""
UPDATE products UPDATE products
SET price = ? SET
WHERE sku = ? price = ?,
price_gg = ?,
price_sales = ?,
insale = ?
WHERE sku = ?
""", data) """, data)
conn.commit() conn.commit()
@ -183,4 +201,4 @@ def update_prices():
# decrypt_and_unpack("prices") # decrypt_and_unpack("prices")
# decrypt_and_unpack("products") # decrypt_and_unpack("products")
# add_product() # add_product()
# update_prices() update_prices()

View File

@ -1,5 +1,6 @@
from flask import Blueprint, request, jsonify from flask import Blueprint, request, jsonify
import sqlite3 import sqlite3
import json
# from services.rokky import ones # from services.rokky import ones
# from API.rok import get_order_content # from API.rok import get_order_content
import logging import logging
@ -20,10 +21,34 @@ def index1():
params = request.args.to_dict() params = request.args.to_dict()
logging.warn(f"newOrder: {params}") logging.warn(f"newOrder: {params}")
# Просто выводим на экран (в ответ клиенту) # Просто выводим на экран (в ответ клиенту)
# парсим данные
return f"Received params: {params}", 200 sku = params.get("id_d")
product_id = params.get("id_i")
email = params.get("email")
price = params.get("amount")
return "Hello GET" # всё остальное сохраняем как JSON
content = json.dumps(params, ensure_ascii=False)
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
try:
cursor.execute("""
INSERT INTO orders (sku, product_id, email, price, content)
VALUES (?, ?, ?, ?, ?)
""", (sku, product_id, email, price, content))
conn.commit()
except Exception as e:
conn.close()
return jsonify({"error": str(e)}), 500
conn.close()
return jsonify({"success": True}), 200
# return "Hello GET"
@main.route("/sales", methods=["POST", "GET"]) @main.route("/sales", methods=["POST", "GET"])
def index2(): def index2():
@ -52,7 +77,7 @@ def new_order():
return jsonify({"status": "ok"}), 200 return jsonify({"status": "ok"}), 200
@main.route("/sku", methods=["POST"]) @main.route("/skuChanged", methods=["POST"])
def sku(): def sku():
if not request.is_json: if not request.is_json:
return jsonify({"error": "Invalid content type"}), 400 return jsonify({"error": "Invalid content type"}), 400