diff --git a/src/glue.py b/src/glue.py index acda22e..55b092f 100644 --- a/src/glue.py +++ b/src/glue.py @@ -106,21 +106,49 @@ async def enrich_single_item(item_id: str, item_data: dict = None, logger=None) # Check if manual price review needed if lego_set.get("requires_manual_price"): - if logger: - logger.info(f"Item {item_id} requires manual price review (≥$110)") - else: - print(f"[@DEBUG] Item {item_id} requires manual price review") + # Get current Square price to check if it's already over $100 + current_price_cents = None + variations = item.get("variations", []) + if variations: + price_money = ( + variations[0].get("item_variation_data", {}).get("price_money", {}) + ) + current_price_cents = price_money.get("amount", 0) - await db.upsert( - "REVIEW", - { - "sq_object": item_id, - "price": lego_set["set_adjustredprice"], - "date_modified": int(time()), - }, - "sq_object", + current_price_dollars = ( + current_price_cents / 100 if current_price_cents else 0 ) + # Only add to review if current price is NOT already over $100 + if current_price_dollars <= 100: + if logger: + logger.info( + f"Item {item_id} requires manual price review (≥$110, current: ${current_price_dollars:.2f})" + ) + else: + print( + f"[@DEBUG] Item {item_id} requires manual price review (current: ${current_price_dollars:.2f})" + ) + + await db.upsert( + "REVIEW", + { + "sq_object": item_id, + "price": lego_set["set_adjustredprice"], + "date_modified": int(time()), + }, + "sq_object", + ) + else: + if logger: + logger.info( + f"Item {item_id} price already over $100 (${current_price_dollars:.2f}), skipping manual review" + ) + else: + print( + f"[@DEBUG] Item {item_id} price already over $100 (${current_price_dollars:.2f}), skipping manual review" + ) + # Update Square item with enriched data success = await asquare.update_itm(item_id, lego_set, item_data=item) diff --git a/studspider.py b/studspider.py index 3574315..87cca51 100644 --- a/studspider.py +++ b/studspider.py @@ -16,16 +16,18 @@ SQUARE_WEBHOOK_URL = sq_env.SQUARE_WEBHOOK_URL SQUARE_LEGO_CAT_ID = sq_env.LEGO_CAT_ID -# Debug: Print configuration (redact key) -if SQUARE_WEBHOOK_SIGNATURE_KEY: - print(f"[CONFIG] Signature key loaded: {SQUARE_WEBHOOK_SIGNATURE_KEY[:10]}...") -else: - print("[CONFIG] WARNING: SQUARE_WEBHOOK_SIGNATURE_KEY not set!") +# Debug: Print configuration only in development or once per process +# When running under gunicorn, the on_starting hook handles this +if not os.getenv("GUNICORN_CMD_ARGS"): + if SQUARE_WEBHOOK_SIGNATURE_KEY: + print(f"[CONFIG] Signature key loaded: {SQUARE_WEBHOOK_SIGNATURE_KEY[:10]}...") + else: + print("[CONFIG] WARNING: SQUARE_WEBHOOK_SIGNATURE_KEY not set!") -if SQUARE_WEBHOOK_URL: - print(f"[CONFIG] Webhook URL: {SQUARE_WEBHOOK_URL}") -else: - print("[CONFIG] WARNING: SQUARE_WEBHOOK_URL not set!") + if SQUARE_WEBHOOK_URL: + print(f"[CONFIG] Webhook URL: {SQUARE_WEBHOOK_URL}") + else: + print("[CONFIG] WARNING: SQUARE_WEBHOOK_URL not set!") # In-memory store for processed event IDs (idempotency) processed_event_ids = set()