time stuff

This commit is contained in:
C committed 2025-10-26 15:48:43 -07:00
1 parent 88dcb8a475
commit 0e3117e408
2 files changed
+16 -10

No files matched your search

+7 -2
View File
@@ -1,15 +1,20 @@
import asyncio import asyncio
import json import json
import re
import get_sq_env import get_sq_env
import aiosqlite import aiosqlite
from time import time
import asquare import asquare
import db import db
import abricksetapi import abricksetapi
from . throttler import GlobalThrottler from throttler import GlobalThrottler
LEGO_CAT_ID = get_sq_env.LEGO_CAT_ID
# big glue boy
async def do_review() -> bool: async def do_review() -> bool:
result = await asquare.acat2id(LEGO_CAT_ID) result = await asquare.acat2id(LEGO_CAT_ID) # type: ignore
for item in result: for item in result:
if not re.match(r".*\d{5}.*", item["name"]): if not re.match(r".*\d{5}.*", item["name"]):
missing = [] missing = []
+9 -8
View File
@@ -4,19 +4,20 @@ from aiohttp import web
from base64 import b64decode from base64 import b64decode
from typing import Dict, Any from typing import Dict, Any
import uuid import uuid
from time import time
import dotenv import dotenv
import os import os
import re import re
import logging import logging
from logging.handlers import RotatingFileHandler from logging.handlers import RotatingFileHandler
from pathlib import Path from pathlib import Path
#print("Creating log directory if it doesn't exist...") print("Creating log directory if it doesn't exist...")
#Path("./logs/").mkdir(parents=True, exist_ok=True) os.makedirs("./logs/", exist_ok=True)
import banner import banner
import get_sq_env import get_sq_env
from time import time
time = int(time())
import asquare as sq import asquare as sq
# from asquareclass import AsyncSquareClient # type: ignore # from asquareclass import AsyncSquareClient # type: ignore
@@ -46,7 +47,7 @@ UA = re.compile(r"^kopling\/?", re.IGNORECASE)
async def run_update(): async def run_update():
set_list = await sq.acat2id(SQUARE_LEGO_CAT_ID) set_list = await sq.acat2id(SQUARE_LEGO_CAT_ID) # type: ignore
#print(f"[@DEBUG]\t {set_list}") # type: ignore #print(f"[@DEBUG]\t {set_list}") # type: ignore
for l_set in set_list: for l_set in set_list:
#print(f"[@DEBUG]{l_set}") #print(f"[@DEBUG]{l_set}")
@@ -85,7 +86,7 @@ async def request_handler(request: web.Request) -> web.Response:
# Verify request method # Verify request method
if request.method != "POST": if request.method != "POST":
logger.error( logger.error(
f"{time()}\tInvalid request method from %s at ", request.remote f"{time}\tInvalid request method from %s at ", request.remote
) )
return web.Response(status=405, text="Method not allowed. Use POST.") return web.Response(status=405, text="Method not allowed. Use POST.")
@@ -114,10 +115,10 @@ async def request_handler(request: web.Request) -> web.Response:
try: try:
decoded_cmd = b64decode(data["CMD"]).decode("utf-8") decoded_cmd = b64decode(data["CMD"]).decode("utf-8")
print( print(
f"""At: {time()}\nReceived command: {decoded_cmd}\nUser-Agent: {request.headers.get('User-Agent')}\nIdempotency-Key: {request.headers.get('Idempotency-Key')}""" f"""At: {time}\nReceived command: {decoded_cmd}\nUser-Agent: {request.headers.get('User-Agent')}\nIdempotency-Key: {request.headers.get('Idempotency-Key')}"""
) )
logging.info( logging.info(
f"{time()}\tCommand: {decoded_cmd}\tFrom: {request.remote}\tUA: {request.headers.get('User-Agent')}\tIdempotency-Key: {request.headers.get('Idempotency-Key')}" f"{time}\tCommand: {decoded_cmd}\tFrom: {request.remote}\tUA: {request.headers.get('User-Agent')}\tIdempotency-Key: {request.headers.get('Idempotency-Key')}"
) )
# Process the command # Process the command