time stuff
This commit is contained in:
1 parent
d1059905c6
commit
8faf56f9ad
2 files changed
+16
-10
No files matched your search
+9
-8
@@ -4,19 +4,20 @@ from aiohttp import web
|
||||
from base64 import b64decode
|
||||
from typing import Dict, Any
|
||||
import uuid
|
||||
from time import time
|
||||
|
||||
import dotenv
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from pathlib import Path
|
||||
#print("Creating log directory if it doesn't exist...")
|
||||
#Path("./logs/").mkdir(parents=True, exist_ok=True)
|
||||
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
|
||||
|
||||
# from asquareclass import AsyncSquareClient # type: ignore
|
||||
@@ -46,7 +47,7 @@ UA = re.compile(r"^kopling\/?", re.IGNORECASE)
|
||||
|
||||
|
||||
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
|
||||
for l_set in set_list:
|
||||
#print(f"[@DEBUG]{l_set}")
|
||||
@@ -85,7 +86,7 @@ async def request_handler(request: web.Request) -> web.Response:
|
||||
# Verify request method
|
||||
if request.method != "POST":
|
||||
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.")
|
||||
|
||||
@@ -114,10 +115,10 @@ async def request_handler(request: web.Request) -> web.Response:
|
||||
try:
|
||||
decoded_cmd = b64decode(data["CMD"]).decode("utf-8")
|
||||
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(
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user