diff --git a/src/asquare.py b/src/asquare.py index 800e6da..2331f68 100644 --- a/src/asquare.py +++ b/src/asquare.py @@ -301,10 +301,7 @@ async def update_itm(item_id: str, lego_set: dict, item_data: dict = None): set_upc = lego_set["set_barcode"] set_image = lego_set["set_image"] pw_name = lego_set["pw_name"] - set_adjustedprice = lego_set["set_adjustredprice"] - - # Convert price to cents for Square API - price_in_cents = int(set_adjustedprice * 100) + # Price updates disabled - enriching without price # Retry logic for version conflicts (race conditions with concurrent updates) max_retries = 3 @@ -386,11 +383,7 @@ async def update_itm(item_id: str, lego_set: dict, item_data: dict = None): "item_variation_data", {} ).copy() - # Update only specific fields - updated_var_data["price_money"] = { - "amount": price_in_cents, - "currency": "USD", - } + # Update only specific fields (price skipped) updated_var_data["sku"] = set_number # LEGO set number updated_var_data["upc"] = ( set_upc if set_upc else None @@ -417,10 +410,6 @@ async def update_itm(item_id: str, lego_set: dict, item_data: dict = None): "item_id": item_id, "name": "Regular", "pricing_type": "FIXED_PRICING", - "price_money": { - "amount": price_in_cents, - "currency": "USD", - }, "sku": set_number, "upc": set_upc if set_upc else None, }, diff --git a/src/glue.py b/src/glue.py index 9ad0e55..49cfc2f 100644 --- a/src/glue.py +++ b/src/glue.py @@ -105,52 +105,10 @@ async def enrich_single_item(item_id: str, item_data: dict = None, logger=None) else: print(f"[@DEBUG] Retrieved Brickset data for {lego_set['pw_name']}") - # Check if manual price review needed - if lego_set.get("requires_manual_price"): - # 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) + # Note: Price updates disabled - enriching without price + # REVIEW table logic skipped - 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 + # Update Square item with enriched data (without price) success = await asquare.update_itm(item_id, lego_set, item_data=item) if success: @@ -208,18 +166,37 @@ async def enrich_bulk(logger=None) -> None: else: print(f"[@DEBUG] Found {len(items)} items in LEGO category") - # Enrich each item + # Enrich each item with concurrent batches successful = 0 failed = 0 + batch_size = 20 # Process 20 items concurrently - for item in items: - item_id = item["id"] - result = await enrich_single_item(item_id, logger=logger) + for i in range(0, len(items), batch_size): + batch = items[i : i + batch_size] + batch_num = (i // batch_size) + 1 + total_batches = (len(items) + batch_size - 1) // batch_size - if result: - successful += 1 + if logger: + logger.info( + f"Processing batch {batch_num}/{total_batches} ({len(batch)} items)" + ) else: - failed += 1 + print( + f"[@DEBUG] Processing batch {batch_num}/{total_batches} ({len(batch)} items)" + ) + + # Process batch concurrently + tasks = [enrich_single_item(item["id"], logger=logger) for item in batch] + results = await asyncio.gather(*tasks, return_exceptions=True) + + # Count results + for result in results: + if isinstance(result, Exception): + failed += 1 + elif result: + successful += 1 + else: + failed += 1 if logger: logger.info(