BIG rename
This commit is contained in:
1 parent
40d9999a80
commit
5440da0bdf
19 files changed
+276
-308
No files matched your search
+162
-161
@@ -1,161 +1,162 @@
|
||||
"""
|
||||
abricksetapi.py - Asynchronous Brickset API Client
|
||||
This module provides asynchronous interactions with the Brickset API.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import aiohttp
|
||||
import json
|
||||
import dotenv
|
||||
from typing import Dict, Any
|
||||
from . import throttler
|
||||
Throttler = throttler.GlobalThrottler
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
|
||||
class AsyncBricksetAPI:
|
||||
"""Asynchronous client for the Brickset API"""
|
||||
|
||||
def __init__(self, debug: bool = False, logger=None):
|
||||
self.username = os.getenv("BRICKSET_USERNAME")
|
||||
self.password = os.getenv("BRICKSET_PASS")
|
||||
self.api_key = os.getenv("BRICKSET_API_KEY")
|
||||
self.debug = debug
|
||||
self.headers = {"UserAgent": "Edderkop/0.1"}
|
||||
self.throttler = Throttler(rate_limit=500, period=60)
|
||||
self.user_hash = None
|
||||
self.logger = logger
|
||||
|
||||
async def login(self) -> Dict[str, Any]:
|
||||
"""Asynchronously authenticate with Brickset API"""
|
||||
url = "https://brickset.com/api/v3.asmx/login"
|
||||
params = {
|
||||
"username": self.username,
|
||||
"password": self.password,
|
||||
"apiKey": self.api_key,
|
||||
}
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(
|
||||
url, params=params, headers=self.headers # type: ignore
|
||||
) as response:
|
||||
if self.debug:
|
||||
print(f"[@DEBUG] Login response status: {response.status}")
|
||||
if self.logger:
|
||||
self.logger.debug(f"Login response status: {response.status}")
|
||||
|
||||
data = await response.read()
|
||||
result = json.loads(data.decode("utf-8"))
|
||||
self.user_hash = result.get("hash")
|
||||
|
||||
if self.logger:
|
||||
self.logger.info("Successfully authenticated with Brickset API")
|
||||
return result
|
||||
|
||||
async def get_set(self, set_number: int) -> Dict[str, Any]:
|
||||
"""
|
||||
Fetch LEGO set information asynchronously
|
||||
|
||||
Args:
|
||||
set_number (str): LEGO set number
|
||||
|
||||
Returns:
|
||||
Dict containing set information
|
||||
"""
|
||||
if not self.user_hash:
|
||||
await self.login()
|
||||
|
||||
url = "https://brickset.com/api/v3.asmx/getSets"
|
||||
params = {
|
||||
"apiKey": self.api_key,
|
||||
"userHash": self.user_hash,
|
||||
"params": json.dumps({"setNumber": f"{set_number}-1"}),
|
||||
}
|
||||
print(f"[@DEBUG] {params}...")
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(
|
||||
url, params=params, headers=self.headers
|
||||
) as response:
|
||||
if self.debug:
|
||||
print(f"[@DEBUG] Get set response status: {response.status}")
|
||||
if self.logger:
|
||||
self.logger.debug(f"Get set response status: {response.status}")
|
||||
|
||||
if response.status == 200:
|
||||
data = await response.read()
|
||||
result = json.loads(data.decode("utf-8"))
|
||||
|
||||
if not result.get("sets"):
|
||||
error_msg = f"No data found for set {set_number}"
|
||||
if self.logger:
|
||||
self.logger.error(error_msg)
|
||||
raise ValueError(error_msg)
|
||||
|
||||
if self.logger:
|
||||
self.logger.info(
|
||||
f"Successfully retrieved data for set {set_number}"
|
||||
)
|
||||
|
||||
set_data = result["sets"][0]
|
||||
our_set = {
|
||||
"set_num": set_data["number"],
|
||||
"set_name": set_data["name"],
|
||||
"set_theme": set_data["theme"],
|
||||
"set_image": set_data["image"]["thumbnailURL"],
|
||||
"set_barcode": set_data["barcode"]["UPC"],
|
||||
"set_retailprice": round(
|
||||
set_data["LEGOCom"]["US"]["retailPrice"]
|
||||
),
|
||||
}
|
||||
|
||||
# Calculate adjusted price (10% markup)
|
||||
retail_price = our_set["set_retailprice"]
|
||||
our_set["set_adjustredprice"] = retail_price + (
|
||||
(10 / 100) * retail_price
|
||||
)
|
||||
|
||||
# Set PW inventory name with theme
|
||||
our_set["pw_name"] = (
|
||||
f"{our_set['set_num']} - {our_set['set_theme'].upper()} {our_set['set_name']}"
|
||||
)
|
||||
|
||||
# Flag for manual price review if needed
|
||||
if our_set["set_retailprice"] >= 110:
|
||||
our_set["requires_manual_price"] = True
|
||||
|
||||
return our_set
|
||||
|
||||
elif response.status == 500:
|
||||
error_msg = (
|
||||
"Internal Server Error: Please check API key and parameters."
|
||||
)
|
||||
if self.logger:
|
||||
self.logger.error(error_msg)
|
||||
raise Exception(error_msg)
|
||||
else:
|
||||
error_msg = f"Unexpected response: {response.status}"
|
||||
if self.logger:
|
||||
self.logger.error(error_msg)
|
||||
raise Exception(error_msg)
|
||||
|
||||
async def throttled_get_set(self, set_number: str) -> Dict[str, Any]:
|
||||
"""Get set information with rate limiting"""
|
||||
async with self.throttler:
|
||||
return await self.get_set(set_number)
|
||||
|
||||
|
||||
async def main():
|
||||
"""Example usage"""
|
||||
client = AsyncBricksetAPI(debug=True)
|
||||
try:
|
||||
set_info = await client.throttled_get_set("10349")
|
||||
print(json.dumps(set_info, indent=2))
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
"""
|
||||
abricksetapi.py - Asynchronous Brickset API Client
|
||||
This module provides asynchronous interactions with the Brickset API.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import aiohttp
|
||||
import json
|
||||
import dotenv
|
||||
from typing import Dict, Any
|
||||
import throttler
|
||||
|
||||
Throttler = throttler.GlobalThrottler
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
|
||||
class AsyncBricksetAPI:
|
||||
"""Asynchronous client for the Brickset API"""
|
||||
|
||||
def __init__(self, debug: bool = False, logger=None):
|
||||
self.username = os.getenv("BRICKSET_USERNAME")
|
||||
self.password = os.getenv("BRICKSET_PASS")
|
||||
self.api_key = os.getenv("BRICKSET_API_KEY")
|
||||
self.debug = debug
|
||||
self.headers = {"UserAgent": "studspider/0.1"}
|
||||
self.throttler = Throttler(rate_limit=500, period=60)
|
||||
self.user_hash = None
|
||||
self.logger = logger
|
||||
|
||||
async def login(self) -> Dict[str, Any]:
|
||||
"""Asynchronously authenticate with Brickset API"""
|
||||
url = "https://brickset.com/api/v3.asmx/login"
|
||||
params = {
|
||||
"username": self.username,
|
||||
"password": self.password,
|
||||
"apiKey": self.api_key,
|
||||
}
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(
|
||||
url, params=params, headers=self.headers # type: ignore
|
||||
) as response:
|
||||
if self.debug:
|
||||
print(f"[@DEBUG] Login response status: {response.status}")
|
||||
if self.logger:
|
||||
self.logger.debug(f"Login response status: {response.status}")
|
||||
|
||||
data = await response.read()
|
||||
result = json.loads(data.decode("utf-8"))
|
||||
self.user_hash = result.get("hash")
|
||||
|
||||
if self.logger:
|
||||
self.logger.info("Successfully authenticated with Brickset API")
|
||||
return result
|
||||
|
||||
async def get_set(self, set_number: int) -> Dict[str, Any]:
|
||||
"""
|
||||
Fetch LEGO set information asynchronously
|
||||
|
||||
Args:
|
||||
set_number (str): LEGO set number
|
||||
|
||||
Returns:
|
||||
Dict containing set information
|
||||
"""
|
||||
if not self.user_hash:
|
||||
await self.login()
|
||||
|
||||
url = "https://brickset.com/api/v3.asmx/getSets"
|
||||
params = {
|
||||
"apiKey": self.api_key,
|
||||
"userHash": self.user_hash,
|
||||
"params": json.dumps({"setNumber": f"{set_number}-1"}),
|
||||
}
|
||||
print(f"[@DEBUG] {params}...")
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(
|
||||
url, params=params, headers=self.headers
|
||||
) as response:
|
||||
if self.debug:
|
||||
print(f"[@DEBUG] Get set response status: {response.status}")
|
||||
if self.logger:
|
||||
self.logger.debug(f"Get set response status: {response.status}")
|
||||
|
||||
if response.status == 200:
|
||||
data = await response.read()
|
||||
result = json.loads(data.decode("utf-8"))
|
||||
|
||||
if not result.get("sets"):
|
||||
error_msg = f"No data found for set {set_number}"
|
||||
if self.logger:
|
||||
self.logger.error(error_msg)
|
||||
raise ValueError(error_msg)
|
||||
|
||||
if self.logger:
|
||||
self.logger.info(
|
||||
f"Successfully retrieved data for set {set_number}"
|
||||
)
|
||||
|
||||
set_data = result["sets"][0]
|
||||
our_set = {
|
||||
"set_num": set_data["number"],
|
||||
"set_name": set_data["name"],
|
||||
"set_theme": set_data["theme"],
|
||||
"set_image": set_data["image"]["thumbnailURL"],
|
||||
"set_barcode": set_data["barcode"]["UPC"],
|
||||
"set_retailprice": round(
|
||||
set_data["LEGOCom"]["US"]["retailPrice"]
|
||||
),
|
||||
}
|
||||
|
||||
# Calculate adjusted price (10% markup)
|
||||
retail_price = our_set["set_retailprice"]
|
||||
our_set["set_adjustredprice"] = retail_price + (
|
||||
(10 / 100) * retail_price
|
||||
)
|
||||
|
||||
# Set PW inventory name with theme
|
||||
our_set["pw_name"] = (
|
||||
f"{our_set['set_num']} - {our_set['set_theme'].upper()} {our_set['set_name']}"
|
||||
)
|
||||
|
||||
# Flag for manual price review if needed
|
||||
if our_set["set_retailprice"] >= 110:
|
||||
our_set["requires_manual_price"] = True
|
||||
|
||||
return our_set
|
||||
|
||||
elif response.status == 500:
|
||||
error_msg = (
|
||||
"Internal Server Error: Please check API key and parameters."
|
||||
)
|
||||
if self.logger:
|
||||
self.logger.error(error_msg)
|
||||
raise Exception(error_msg)
|
||||
else:
|
||||
error_msg = f"Unexpected response: {response.status}"
|
||||
if self.logger:
|
||||
self.logger.error(error_msg)
|
||||
raise Exception(error_msg)
|
||||
|
||||
async def throttled_get_set(self, set_number: str) -> Dict[str, Any]:
|
||||
"""Get set information with rate limiting"""
|
||||
async with self.throttler:
|
||||
return await self.get_set(set_number)
|
||||
|
||||
|
||||
async def main():
|
||||
"""Example usage"""
|
||||
client = AsyncBricksetAPI(debug=True)
|
||||
try:
|
||||
set_info = await client.throttled_get_set("10349")
|
||||
print(json.dumps(set_info, indent=2))
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
+10
-6
@@ -6,9 +6,9 @@ import uuid
|
||||
import re
|
||||
from time import time
|
||||
|
||||
from . import db
|
||||
import db
|
||||
|
||||
from . import get_sq_env
|
||||
import get_sq_env
|
||||
|
||||
|
||||
def get_set_number(text: str) -> int:
|
||||
@@ -106,10 +106,14 @@ async def acat2id(cat_id: str):
|
||||
{
|
||||
"id": obj["id"],
|
||||
"name": obj.get("item_data", {}).get("name", "Unknown"),
|
||||
"number": None if not obj.get("item_data", {}).get("name", "") else (
|
||||
get_set_number(obj.get("item_data", {}).get("name", ""))
|
||||
if re.findall(r"\d{5}", obj.get("item_data", {}).get("name", ""))
|
||||
else None
|
||||
"number": (
|
||||
None
|
||||
if not obj.get("item_data", {}).get("name", "")
|
||||
else (
|
||||
get_set_number(obj.get("item_data", {}).get("name", ""))
|
||||
if re.findall(r"\d{5}", obj.get("item_data", {}).get("name", ""))
|
||||
else None
|
||||
)
|
||||
),
|
||||
"updated_at": obj.get("updated_at"),
|
||||
"version": obj.get("version"),
|
||||
|
||||
+2
-2
@@ -14,9 +14,9 @@ debug = False # Set to True to enable debug output
|
||||
|
||||
def login(username, password):
|
||||
url = "https://brickset.com/api/v3.asmx/login"
|
||||
headers = {"UserAgent": "Edderkop/0.1"}
|
||||
headers = {"UserAgent": "studspider/0.1"}
|
||||
params = {
|
||||
"UserAgent": "Edderkop/0.1",
|
||||
"UserAgent": "studspider/0.1",
|
||||
"username": username,
|
||||
"password": password,
|
||||
"apiKey": BRICKSET_API_KEY,
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import aiosqlite
|
||||
from time import time
|
||||
|
||||
time = int(time()) # we dont need no stinkin floats
|
||||
|
||||
# db = await aiosqlite.connect("edderkop.db") # type: ignore
|
||||
# db = await aiosqlite.connect("studspider.db") # type: ignore
|
||||
|
||||
|
||||
async def close(db):
|
||||
await db.close()
|
||||
|
||||
|
||||
async def fetch(table, sqobj):
|
||||
"""
|
||||
Asynchronously fetch a record from the REVIEW table by sq_object.
|
||||
@@ -16,13 +19,16 @@ async def fetch(table, sqobj):
|
||||
Returns:
|
||||
dict or None: The fetched record as a dictionary, or None if not found.
|
||||
"""
|
||||
async with aiosqlite.connect("edderkop.db") as db: # type: ignore
|
||||
async with db.execute(f"SELECT * FROM {table} WHERE sq_object = {sqobj}") as cursor:
|
||||
async with aiosqlite.connect("studspider.db") as db: # type: ignore
|
||||
async with db.execute(
|
||||
f"SELECT * FROM {table} WHERE sq_object = {sqobj}"
|
||||
) as cursor:
|
||||
async for row in cursor:
|
||||
return row
|
||||
|
||||
return None
|
||||
|
||||
|
||||
async def upsert(table: str, data: dict, unique_key: str) -> bool:
|
||||
"""
|
||||
Asynchronously insert or update a record in the specified table.
|
||||
@@ -37,9 +43,11 @@ async def upsert(table: str, data: dict, unique_key: str) -> bool:
|
||||
"""
|
||||
print(f"Upserting into {table}: {data}")
|
||||
|
||||
columns = ', '.join(data.keys())
|
||||
placeholders = ', '.join('?' * len(data))
|
||||
updates = ', '.join(f"{col}=excluded.{col}" for col in data.keys() if col != unique_key)
|
||||
columns = ", ".join(data.keys())
|
||||
placeholders = ", ".join("?" * len(data))
|
||||
updates = ", ".join(
|
||||
f"{col}=excluded.{col}" for col in data.keys() if col != unique_key
|
||||
)
|
||||
|
||||
sql = f"""
|
||||
INSERT INTO {table} ({columns})
|
||||
@@ -47,7 +55,7 @@ async def upsert(table: str, data: dict, unique_key: str) -> bool:
|
||||
ON CONFLICT({unique_key}) DO UPDATE SET
|
||||
{updates};
|
||||
"""
|
||||
async with aiosqlite.connect("edderkop.db") as db: # type: ignore
|
||||
async with aiosqlite.connect("studspider.db") as db: # type: ignore
|
||||
async with db.execute(sql, tuple(data.values())) as cursor:
|
||||
await db.commit()
|
||||
return True
|
||||
+1
-1
@@ -15,7 +15,7 @@ class BricksetAPI:
|
||||
self.password = os.getenv("BRICKSET_PASS")
|
||||
self.api_key = os.getenv("BRICKSET_API_KEY")
|
||||
self.debug = debug
|
||||
self.headers = {"UserAgent": "Edderkop/0.1"}
|
||||
self.headers = {"UserAgent": "studspider/0.1"}
|
||||
self.user_hash = None
|
||||
|
||||
def login(self) -> Dict[str, Any]:
|
||||
|
||||
+5
-5
@@ -6,21 +6,21 @@ import os
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Get the absolute path to edderkop.db in the project root
|
||||
# Get the absolute path to studspider.db in the project root
|
||||
DEFAULT_DB_PATH = os.path.join(
|
||||
os.path.dirname(os.path.dirname(__file__)), "edderkop.db"
|
||||
os.path.dirname(os.path.dirname(__file__)), "studspider.db"
|
||||
)
|
||||
|
||||
if not os.path.exists(DEFAULT_DB_PATH):
|
||||
raise FileNotFoundError(f"Database file not found at {DEFAULT_DB_PATH}")
|
||||
print('Please run "src/scripts/EDDERKOP.SQL" to setup the database.')
|
||||
print('Please run "src/scripts/studspider.SQL" to setup the database.')
|
||||
os.exit(0)
|
||||
|
||||
|
||||
class AsyncSchedulerDB:
|
||||
"""
|
||||
Asynchronous SQLite database manager for APScheduler.
|
||||
Handles job storage, retrieval, and database operations using the main edderkop.db database.
|
||||
Handles job storage, retrieval, and database operations using the main studspider.db database.
|
||||
"""
|
||||
|
||||
def __init__(self, db_path: str = DEFAULT_DB_PATH):
|
||||
@@ -29,7 +29,7 @@ class AsyncSchedulerDB:
|
||||
|
||||
Args:
|
||||
db_path (str, optional): Path to the SQLite database file.
|
||||
Defaults to edderkop.db in project root.
|
||||
Defaults to studspider.db in project root.
|
||||
"""
|
||||
self.db_path = db_path
|
||||
self._initialized = False
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@ async def handle_post(request):
|
||||
return True
|
||||
else:
|
||||
return aiohttp.web.Response(status=400, text="400 Bad Request.")
|
||||
result = {"message": f"Edderkop/0.1 received command: {reqdata}"}
|
||||
result = {"message": f"studspider/0.1 received command: {reqdata}"}
|
||||
return aiohttp.web.json_response(status=200, data=result)
|
||||
|
||||
|
||||
@@ -108,6 +108,6 @@ async def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(generate_toilet_banner("Edderkop v0.1"))
|
||||
print(generate_toilet_banner("studspider v0.1"))
|
||||
print("Built for PLAY-WELL TEKNOLOGIES by contact@traps.moe\n\n")
|
||||
aiohttp.web.run_app(app, port=7432)
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.2 KiB |
@@ -1,2 +0,0 @@
|
||||
|
||||
reflex==0.8.14.post1
|
||||
@@ -1,9 +0,0 @@
|
||||
import reflex as rx
|
||||
|
||||
config = rx.Config(
|
||||
app_name="web",
|
||||
plugins=[
|
||||
rx.plugins.SitemapPlugin(),
|
||||
rx.plugins.TailwindV4Plugin(),
|
||||
]
|
||||
)
|
||||
Whitespace-only changes.
@@ -1,36 +0,0 @@
|
||||
"""Welcome to Reflex! This file outlines the steps to create a basic app."""
|
||||
|
||||
import reflex as rx
|
||||
|
||||
from rxconfig import config
|
||||
|
||||
|
||||
class State(rx.State):
|
||||
"""The app state."""
|
||||
|
||||
|
||||
def index() -> rx.Component:
|
||||
# Welcome Page (Index)
|
||||
return rx.container(
|
||||
rx.color_mode.button(position="top-right"),
|
||||
rx.vstack(
|
||||
rx.heading("Welcome to Reflex!", size="9"),
|
||||
rx.text(
|
||||
"Get started by editing ",
|
||||
rx.code(f"{config.app_name}/{config.app_name}.py"),
|
||||
size="5",
|
||||
),
|
||||
rx.link(
|
||||
rx.button("Check out our docs!"),
|
||||
href="https://reflex.dev/docs/getting-started/introduction/",
|
||||
is_external=True,
|
||||
),
|
||||
spacing="5",
|
||||
justify="center",
|
||||
min_height="85vh",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
app = rx.App()
|
||||
app.add_page(index)
|
||||
+14
-13
@@ -11,12 +11,14 @@ import re
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from pathlib import Path
|
||||
|
||||
print("Creating log directory if it doesn't exist...")
|
||||
os.makedirs("./logs/", exist_ok=True)
|
||||
|
||||
import banner
|
||||
import get_sq_env
|
||||
from time import time
|
||||
|
||||
time = int(time())
|
||||
import asquare as sq
|
||||
|
||||
@@ -31,15 +33,15 @@ from asyncio_throttle.throttler import Throttler
|
||||
|
||||
# set up logger
|
||||
print("Setting up logger...")
|
||||
logger = logging.getLogger("edderkop")
|
||||
logger = logging.getLogger("studspider")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
handler = RotatingFileHandler("./logs/edderkop.log", maxBytes=125000, backupCount=5)
|
||||
handler = RotatingFileHandler("./logs/studspider.log", maxBytes=125000, backupCount=5)
|
||||
logger.addHandler(handler)
|
||||
|
||||
lego = AsyncBricksetAPI(debug=True, logger=logger)
|
||||
# sq = AsyncSquareClient(logger=logger)
|
||||
# logging.basicConfig(
|
||||
# filename="./logs/edderkop.log", encoding="utf-8", level=logging.DEBUG
|
||||
# filename="./logs/studspider.log", encoding="utf-8", level=logging.DEBUG
|
||||
# )
|
||||
print("Setting up rate limiter...")
|
||||
print("Doing RE things...")
|
||||
@@ -47,10 +49,10 @@ UA = re.compile(r"^kopling\/?", re.IGNORECASE)
|
||||
|
||||
|
||||
async def run_update():
|
||||
set_list = await sq.acat2id(SQUARE_LEGO_CAT_ID) # type: ignore
|
||||
#print(f"[@DEBUG]\t {set_list}") # type: ignore
|
||||
set_list = await sq.acat2id(SQUARE_LEGO_CAT_ID) # type: ignore
|
||||
# print(f"[@DEBUG]\t {set_list}") # type: ignore
|
||||
for l_set in set_list:
|
||||
#print(f"[@DEBUG]{l_set}")
|
||||
# print(f"[@DEBUG]{l_set}")
|
||||
try:
|
||||
l_setinfo = await lego.throttled_get_set(l_set["number"])
|
||||
print(f"[@DEBUG] Found {l_setinfo["pw_name"]}")
|
||||
@@ -58,8 +60,8 @@ async def run_update():
|
||||
print(f"Error fetching set\t: {l_set}: {str(e)}")
|
||||
continue
|
||||
|
||||
#print(f"[@DEBUG]{l_setinfo}")
|
||||
#await sq.update_itm(l_set, l_setinfo)
|
||||
# print(f"[@DEBUG]{l_setinfo}")
|
||||
# await sq.update_itm(l_set, l_setinfo)
|
||||
"""for l_set in set_list:
|
||||
print(f"[@DEBUG]{l_set}")
|
||||
try:
|
||||
@@ -85,9 +87,7 @@ async def request_handler(request: web.Request) -> web.Response:
|
||||
try:
|
||||
# Verify request method
|
||||
if request.method != "POST":
|
||||
logger.error(
|
||||
f"{time}\tInvalid request method from %s at ", request.remote
|
||||
)
|
||||
logger.error(f"{time}\tInvalid request method from %s at ", request.remote)
|
||||
return web.Response(status=405, text="Method not allowed. Use POST.")
|
||||
|
||||
# Get JSON data from request
|
||||
@@ -138,12 +138,13 @@ async def request_handler(request: web.Request) -> web.Response:
|
||||
print(f"Request handler error: {str(e)}")
|
||||
return web.Response(status=500, text="Internal server error")
|
||||
|
||||
|
||||
print("Starting web server...")
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
os.system("cls" if os.name == "nt" else "clear")
|
||||
app = web.Application()
|
||||
app.router.add_post("/", request_handler)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(banner.generate("Edderkop v0.1"))
|
||||
print(banner.generate("studspider v0.1"))
|
||||
print("Built for PLAY-WELL TEKNOLOGIES by contact@traps.moe\n\n")
|
||||
web.run_app(app, host="localhost", port=7432)
|
||||
Reference in new issue
Block a user