From dbe5cd6146d8d8af047a08f325f6bffa4e77036e Mon Sep 17 00:00:00 2001 From: C <0xicl33n@gmail.com> Date: Wed, 7 Jan 2026 09:59:36 -0800 Subject: [PATCH] final commit before first prod test --- config/gunicorn.conf.py | 1 + src/abricksetapi.py | 6 ++++-- src/get_sq_env.py | 6 +++++- src/glue.py | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/config/gunicorn.conf.py b/config/gunicorn.conf.py index 9de876b..d3272d4 100644 --- a/config/gunicorn.conf.py +++ b/config/gunicorn.conf.py @@ -91,6 +91,7 @@ def when_ready(server): print("\n".join(banner_lines)) print("Built for PLAY-WELL TEKNOLOGIES by contact@studspider.sh\n\n") + print("PRODUCTION MODE\n" if os.getenv("SQUARE_ENV") == "production" else "SANDBOX MODE\n") print(f"HOST:\t{bind}") print(f"WORKERS:\t{workers}") print(f"WORKER TYPE:\t{worker_class}") diff --git a/src/abricksetapi.py b/src/abricksetapi.py index 295393c..17d83d6 100644 --- a/src/abricksetapi.py +++ b/src/abricksetapi.py @@ -13,6 +13,7 @@ from typing import Dict, Any, Optional from datetime import datetime, timedelta from async_lru import alru_cache from . import throttler +from . import get_sq_env Throttler = throttler.GlobalThrottler @@ -22,11 +23,12 @@ dotenv.load_dotenv() class AsyncBricksetAPI: """Asynchronous client for the Brickset API""" - def __init__(self, debug: bool = False, logger=None): + def __init__(self, debug: bool = None, 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 + # Use DEBUG_MODE from env if debug not explicitly set + self.debug = debug if debug is not None else get_sq_env.DEBUG_MODE self.headers = {"UserAgent": "studspider/0.1"} self.throttler = Throttler(rate_limit=500, period=60) self.user_hash = None diff --git a/src/get_sq_env.py b/src/get_sq_env.py index 566af8a..bb28a24 100644 --- a/src/get_sq_env.py +++ b/src/get_sq_env.py @@ -11,7 +11,11 @@ LEGO_CAT_ID = os.getenv("SQUARE_LEGO_CAT_ID") SQUARE_WEBHOOK_URL = os.getenv("SQUARE_WEBHOOK_URL") -if os.getenv("SQUARE_ENV") == "production": +# Check environment mode +IS_PRODUCTION = os.getenv("SQUARE_ENV") == "production" +DEBUG_MODE = not IS_PRODUCTION # Debug logging enabled in sandbox/dev + +if IS_PRODUCTION: SQUARE_APP_ID = os.getenv("PROD_SQUARE_APP_ID") SQUARE_TOKEN = os.getenv("PROD_SQUARE_TOKEN") SQUARE_WEBHOOK_SIGNATURE_KEY = os.getenv("PROD_SQUARE_WEBHOOK_SIGNATURE_KEY") diff --git a/src/glue.py b/src/glue.py index 55b092f..9ad0e55 100644 --- a/src/glue.py +++ b/src/glue.py @@ -96,7 +96,8 @@ async def enrich_single_item(item_id: str, item_data: dict = None, logger=None) print(f"[@DEBUG] Extracted set number: {set_number}") # Fetch Brickset data (with throttling) - brickset_client = abricksetapi.AsyncBricksetAPI(debug=True, logger=logger) + # debug flag will be auto-set based on SQUARE_ENV + brickset_client = abricksetapi.AsyncBricksetAPI(logger=logger) lego_set = await brickset_client.throttled_get_set(set_number) if logger: