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