add verbosity to startup
This commit is contained in:
1 parent
7f5210ab57
commit
43e19b200d
1 file changed
+23
-14
+23
-14
@@ -11,42 +11,52 @@ 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)
|
||||
|
||||
import banner
|
||||
import get_sq_env
|
||||
|
||||
import asquare as sq
|
||||
|
||||
# from asquareclass import AsyncSquareClient # type: ignore
|
||||
from abricksetapi import AsyncBricksetAPI
|
||||
|
||||
|
||||
print("Loading environment variables...")
|
||||
dotenv.load_dotenv()
|
||||
SQUARE_LEGO_CAT_ID = os.environ.get("SQUARE_LEGO_CAT_ID")
|
||||
|
||||
|
||||
from asyncio_throttle.throttler import Throttler
|
||||
|
||||
# set up logger
|
||||
print("Setting up logger...")
|
||||
logger = logging.getLogger("edderkop")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
handler = RotatingFileHandler("./logs/", maxBytes=1024, backupCount=5)
|
||||
handler = RotatingFileHandler("./logs/edderkop.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
|
||||
# )
|
||||
|
||||
print("Setting up rate limiter...")
|
||||
print("Doing RE things...")
|
||||
UA = re.compile(r"^kopling\/?", re.IGNORECASE)
|
||||
|
||||
|
||||
async def run_update():
|
||||
set_list = await sq.acat2id(SQUARE_LEGO_CAT_ID) # type: ignore
|
||||
for l_set in set_list:
|
||||
set_list = await sq.acat2id(SQUARE_LEGO_CAT_ID)
|
||||
print(f"[@DEBUG]\t {set_list}") # type: ignore
|
||||
"""for l_set in set_list:
|
||||
print(f"[@DEBUG]{l_set}")
|
||||
l_setinfo = await lego.throttled_get_set(l_set["number"])
|
||||
print(f"[@DEBUG]{l_setinfo}")
|
||||
try:
|
||||
l_setinfo = await lego.throttled_get_set(l_set["number"])
|
||||
except Exception as e:
|
||||
print(f"Error fetching set\t: {l_set}: {str(e)}")
|
||||
continue
|
||||
|
||||
print(f"[@DEBUG]{l_setinfo}")"""
|
||||
# await sq.update_itm(l_set, l_setinfo)
|
||||
|
||||
|
||||
@@ -101,11 +111,9 @@ async def request_handler(request: web.Request) -> web.Response:
|
||||
|
||||
# Process the command
|
||||
if decoded_cmd == "RUNUPDATE":
|
||||
# Add your command handling logic here
|
||||
await run_update()
|
||||
response_data = {"status": "success", "message": "Update started"}
|
||||
await run_update()
|
||||
logging.info(f"{time()}\tUpdate command processed successfully")
|
||||
|
||||
return web.json_response(response_data)
|
||||
else:
|
||||
return web.Response(status=400, text=f"Unknown command: {decoded_cmd}")
|
||||
@@ -118,7 +126,8 @@ 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')
|
||||
app = web.Application()
|
||||
app.router.add_post("/", request_handler)
|
||||
|
||||
|
||||
Reference in new issue
Block a user