diff --git a/API/__pycache__/rok.cpython-313.pyc b/API/__pycache__/rok.cpython-313.pyc index e4d55f8..bb34c4f 100644 Binary files a/API/__pycache__/rok.cpython-313.pyc and b/API/__pycache__/rok.cpython-313.pyc differ diff --git a/API/__pycache__/rokky.cpython-313.pyc b/API/__pycache__/rokky.cpython-313.pyc index aae78ff..6c21fdc 100644 Binary files a/API/__pycache__/rokky.cpython-313.pyc and b/API/__pycache__/rokky.cpython-313.pyc differ diff --git a/API/rok.py b/API/rok.py index 45049a4..8f74747 100644 --- a/API/rok.py +++ b/API/rok.py @@ -1,8 +1,10 @@ from dotenv import load_dotenv import os load_dotenv() - +import sqlite3 import requests + +conn = sqlite3.connect("./files/rokky.db") partner = os.getenv('partner') user_name = os.getenv('userName') password = os.getenv('password') @@ -78,8 +80,10 @@ def download_prices(): print("Каталог цен скачан.") -def create_order(sku, quantity, unit_price, partner_order_id): +def create_order(sku, unit_price, partner_order_id): # try: + conn = sqlite3.connect("./files/rokky.db") + cursor = conn.cursor() url = f"{BASE_URL}/orders" headers = { @@ -91,11 +95,11 @@ def create_order(sku, quantity, unit_price, partner_order_id): "items": [ { "sku": int(sku), - "quantity": int(quantity), + "quantity": 1, "unitPrice": float(unit_price) } ], - "partnerOrderId": partner_order_id + "partnerOrderId": f"my-orders{partner_order_id}" } try: @@ -117,7 +121,18 @@ def create_order(sku, quantity, unit_price, partner_order_id): response.raise_for_status() # Всё равно выбрасываем исключение - return response.json() + r = response.json() + order_id = r["orderId"] + print(partner_order_id) + print(order_id) + cursor.execute(""" + UPDATE orders + SET orders_rokky = ? + WHERE id_i = ? + """, (order_id, partner_order_id)) + + conn.commit() + conn.close() except requests.exceptions.RequestException as e: print(f"🌐 Сетевая ошибка: {e}") @@ -146,6 +161,7 @@ def get_orders(page=1, page_size=25): def get_order_content(order_id): + cursor = conn.cursor() url = f"{BASE_URL}/orders/{order_id}/content" headers = { @@ -156,20 +172,31 @@ def get_order_content(order_id): response = requests.get(url, headers=headers) response.raise_for_status() data = response.json() + con = data['orderContentItems'] for c in con: content = c['content'] + + cursor.execute(""" + UPDATE orders + SET key = ? + WHERE orders_rokky = ? + """, (content, order_id)) + + conn.commit() + conn.close() + return content -# content = get_order_content(5379499) +content = get_order_content(5388351) # print(content) # orders = get_orders() # print(orders) -# order = create_order(22774, 1, 21.3, "my-test-order-12w3") +# order = create_order(22785, 22.63, "my-test-order-122w3") # print(order) diff --git a/API/rokky.py b/API/rokky.py index 596eb4c..5b048f4 100644 --- a/API/rokky.py +++ b/API/rokky.py @@ -201,4 +201,4 @@ def update_prices(): # decrypt_and_unpack("prices") # decrypt_and_unpack("products") # add_product() -update_prices() \ No newline at end of file +# update_prices() \ No newline at end of file diff --git a/API/ww b/API/ww index 9ec6946..d61c1aa 100644 --- a/API/ww +++ b/API/ww @@ -1 +1 @@ -5110eb4a7aa7c60d66f9648db40027f241c52673a6a7c9a136e2a02fd1711fb&amount=1.0¤cy=RUB&date=2026-03-20T10=43=09+03=00&email=rusinowdima2@yandex.ru&id_d=102180432&id_i=21327450&ip=188.32.208.151&is_my_product=true \ No newline at end of file +id_i=34534345435&id_d=102180432&amount=33&curr=USD&date=2026-03-20T10:43:09+03:00&email=rusinowdima2@yandex.ru&sha256=5110eb4a7aa7c60d66f9648db40027f241c52673a6a7c9a136e27a02fd1711fb&ip={IP}&isMyProduct=true \ No newline at end of file diff --git a/app/__pycache__/routes.cpython-313.pyc b/app/__pycache__/routes.cpython-313.pyc index 7933f18..c8b76f9 100644 Binary files a/app/__pycache__/routes.cpython-313.pyc and b/app/__pycache__/routes.cpython-313.pyc differ diff --git a/app/routes.py b/app/routes.py index f0651e9..8e33f1c 100644 --- a/app/routes.py +++ b/app/routes.py @@ -7,6 +7,9 @@ import json from API.rok import create_order from API.TG import send_telegram from services.orders import get_sku +from services.gg import get_product, create_messagea +from services.send_mai import send_html_flow + import logging @@ -31,16 +34,23 @@ def index1(): logging.warn(f"newOrder: {params}") # Просто выводим на экран (в ответ клиенту) # парсим данные - sku = params.get("id_d") - product_id = params.get("id_i") + id_d = params.get("id_d") + id_i = params.get("id_i") email = params.get("email") - price = params.get("amount") - + amount = params.get("amount") + currency = params.get("currency") + date = params.get("date") # всё остальное сохраняем как JSON content = json.dumps(params, ensure_ascii=False) - db_sku, db_price = get_sku(sku) - create_order(db_sku, price, db_price, f"my-test-order-{product_id}") - # send_telegram(content) + + + message = f"🔹Спасибо за покупку в WST Keys (West Store Trusted Keys)\n\n ⏳ Ваш заказ находится в процессе отгрузки." + create_messagea(id_i, message) + name_p, im = get_product(id_d) + sku_rokky, price_rokky = get_sku(id_d) + + + send_telegram(content) conn = sqlite3.connect(DB_PATH) cursor = conn.cursor() @@ -48,9 +58,9 @@ def index1(): try: cursor.execute(""" - INSERT INTO orders (sku, product_id, email, price, content) - VALUES (?, ?, ?, ?, ?) - """, (sku, product_id, email, price, content)) + INSERT INTO orders (id_i, id_d, email,name_p, im, amount, content, currency, date, sku_rokky, price_rokky) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?) + """, (id_i, id_d, email, name_p, im, amount, content, currency, date, sku_rokky, price_rokky)) conn.commit() except Exception as e: @@ -58,15 +68,12 @@ def index1(): return jsonify({"error": str(e)}), 500 conn.close() + create_order(sku_rokky, price_rokky, id_i) return jsonify({"success": True}), 200 # return "Hello GET" -@main.route("/sales", methods=["POST", "GET"]) -def index2(): - return "Hello GET!!!++!!ss" - @main.route("/newOrder", methods=["POST"]) def new_order(): @@ -87,6 +94,10 @@ def new_order(): send_telegram(data) # logging.warn(get_order_content(order_id)) logging.warn(f"newOrder: {order_id}") + get_order_content(order_id) + send_html_flow(order_id) + + return jsonify({"status": "ok"}), 200 diff --git a/models/orders.py b/models/orders.py index 946bd17..774c877 100644 --- a/models/orders.py +++ b/models/orders.py @@ -6,10 +6,19 @@ cursor = conn.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS orders ( id INTEGER PRIMARY KEY AUTOINCREMENT, - sku INTEGER UNIQUE, - product_id INTEGER, + id_i INTEGER UNIQUE, + id_d INTEGER, + name_p TEXT, + im TEXT, email TEXT, - price TEXT, + chat_id TEXT, + currency TEXT, + amount TEXT, + date TEXT, + sku_rokky TEXT, + price_rokky TEXT, + orders_rokky TEXT, + key TEXT, content TEXT ) """) diff --git a/services/gg.py b/services/gg.py index b3d9c33..a149122 100644 --- a/services/gg.py +++ b/services/gg.py @@ -212,9 +212,9 @@ def get_chats(page=1, pagesize=20, filter_new=None, email=None, id_ds=None): return r.json() -def get_product(): +def get_product(product_id): token = load_token() - product_id = 102182541 + # product_id = 102180432 url = f"https://seller.ggsel.com/api_sellers/api/products/{product_id}/data" @@ -229,10 +229,14 @@ def get_product(): r = requests.get(url, headers=headers, params=params) print(r.status_code) - return r.json() + prud = r.json() + name = prud["product"]["name"] + im = prud["product"]["preview_imgs"][0]["url"] + return name, im + # return r.json() -# print(get_product()) +# print(get_product(102182541)) def create_message(id_i: int): @@ -268,10 +272,91 @@ def create_message(id_i: int): } # пример вызова -create_message(18094706) +# create_message(18094706) + +def create_messagea(id_i: int, message): + print("SEND MESSAGE CALLED", id_i) + + token = load_token() + # message = "Спасибо за покупку в WST Keys" + + url = "https://seller.ggsel.com/api_sellers/api/debates/v2" + + params = { + "token": token, + "id_i": id_i + } + + payload = { + "message": message + } + + r = requests.post(url, params=params, json=payload) + + print("STATUS:", r.status_code) + + return r.text +# message = f"🔹Спасибо за покупку в WST Keys (West Store Trusted Keys)\n\n" +# create_messagea(22273227, message) # пример -# print(get_chats()) + +def get_chats_by_email(email): + token = load_token() + message = ( + f"" + +) + + url = "https://seller.ggsel.com/api_sellers/api/debates/v2/chats" + + params = { + "token": token, + 'email': email, + 'pagesize': 100, + 'page': 1 + } + + payload = { + "message": message + } + + r = requests.get(url, params=params) + print(r.text) + if r.status_code == 200: + return {"success": True} + + return { + "success": False, + "status": r.status_code, + "response": r.text + } + +# get_chats_by_email('fenomenplayerok@gmail.com') + + +def get_order_info(invoice_id: int, locale: str = "ru"): + token = load_token() + url = f"https://seller.ggsel.com/api_sellers/api/purchase/info/{invoice_id}" + + headers = { + "Accept": "application/json", + "locale": locale + } + + params = { + "token": token + } + + r = requests.get(url, headers=headers, params=params) + return r.json() # или r.text если нужен сырой ответ + +# # пример использования + +# invoice_id = 22228752 +# info = get_order_info(invoice_id) +# print(info) +# print(get_chats(email='fenomenplayerok@gmail.com')) # def tokens(): # timestamp = str(int(time.time())) @@ -313,4 +398,24 @@ create_message(18094706) # response = requests.get(url, params=params, headers=headers) # print(response.status_code) -# print(response.json()) \ No newline at end of file +# print(response.json()) + + +# def create_debate(order_id): +# token = load_token() +# url = "https://seller.ggsel.com/api_sellers/api/debates/v2" + +# params = { +# "token": token, +# "id_i": order_id +# } + +# json = { +# "message": "Спасибо за покупку в WST Keys" +# } + +# r = requests.post(url, params=params, json=json) +# return r.json() + + +# print(create_debate("22257737")) \ No newline at end of file diff --git a/services/send_mai.py b/services/send_mai.py index b77289d..2bd6f70 100644 --- a/services/send_mai.py +++ b/services/send_mai.py @@ -1,5 +1,8 @@ import sys from mailer import send_plain_email, send_html_email +import sqlite3 +from datetime import datetime +from gg import create_messagea def read_multiline(prompt: str) -> str: @@ -24,43 +27,59 @@ def send_text_flow(): send_plain_email(to_addr, subject, body) -def send_html_flow(): - to_addr = input("Receiver email: ").strip() +def send_html_flow(ids): + # to_addr = input("Receiver email: ").strip() + + conn = sqlite3.connect("./files/rokky.db") + cursor = conn.cursor() + sku = ids + + cursor.execute(""" + SELECT * + FROM orders + WHERE orders_rokky = ? + """, (sku,)) + + rows = cursor.fetchall() + for row in rows: + print(row) + + + conn.close() + s = row[9] + s = s.replace(" ", "+", 1) # только первое вхождение после времени + dt = datetime.fromisoformat(s) + dates = dt.strftime("%Y-%m-%d %H:%M:%S") data = { - "company_name": "wstkeys", - "order_id": "123", - "customer_name": "4321", - "currency": "USD", + # "company_name": "wstkeys", + "order_id": row[1], + # "customer_name": "4321", + "currency": row[7], "items": [ - {"name": "Game 1333", "quantity": 1, "price": 1330}, + {"name": row[3], "quantity": 1, "price": row[8]}, ], - "date": "23.03.2026 14:02", - "product_name": "Railroads Online - Pioneer DLC", - "product_image": "https://s3.ggsel.com/gsellers-imgs-prod/e05c8d1f28e18f56334bf8e7e9f7b547.jpeg", - "total_price": 20, - "key": 'XXXX-XXXX-YYY23', + "date": dates, + "product_name": row[3], + "product_image": row[4], + "total_price": row[8], + "key": row[13], "support_email": "wstkeys@gmail.com", "year": 2026 } - - send_html_email(to_addr, data) + to_addr = row[5] + # send_html_email(to_addr, data) + message = ( + f"🔹Спасибо за покупку в WST Keys (West Store Trusted Keys)\n\n" + f"🔑 Ваш ключ: {row[13]}\n\n" + "📩 Копия ключа отправлена на вашу электронную почту.\n" + "💬 Если у вас возникнут вопросы — напишите нам.\n" + "⭐️ Нам очень важно ваше мнение, пожалуйста, оставьте отзыв." + ) + create_messagea(row[0], message ) + + -def main(): - print("1 - Send plain email") - print("2 - Send HTML email") - - choice = input("Choose: ").strip() - - if choice == "1": - send_text_flow() - elif choice == "2": - send_html_flow() - else: - print("Invalid choice") - - -if __name__ == "__main__": - main() \ No newline at end of file +# send_html_flow(5388351) \ No newline at end of file diff --git a/services/test.py b/services/test.py new file mode 100644 index 0000000..8c3498b --- /dev/null +++ b/services/test.py @@ -0,0 +1,25 @@ +import sqlite3 +from datetime import datetime +conn = sqlite3.connect("./files/rokky.db") +cursor = conn.cursor() + +sku = '5388258' + +cursor.execute(""" + SELECT * + FROM orders + WHERE orders_rokky = ? +""", (sku,)) + +rows = cursor.fetchall() + +for row in rows: + print(row[3]) + +s = row[8] +s = s.replace(" ", "+", 1) # только первое вхождение после времени +dt = datetime.fromisoformat(s) +result = dt.strftime("%Y-%m-%d %H:%M:%S") + +print(result) +conn.close() \ No newline at end of file diff --git a/templates/welcome.html b/templates/welcome.html index e811837..57cac39 100644 --- a/templates/welcome.html +++ b/templates/welcome.html @@ -1,18 +1,20 @@ - + - +
logo + style="max-width:400px; height:auto;">
-

Спасибо за покупку в WST Keys (West Store Trusted Keys)

+

+ Спасибо за покупку в WST Keys (West Store Trusted Keys) +