diff --git a/src/list_categories.py b/src/list_categories.py new file mode 100644 index 0000000..51ab61a --- /dev/null +++ b/src/list_categories.py @@ -0,0 +1,90 @@ +""" +List all Square categories with their IDs to help identify the correct LEGO category ID +""" + +import asyncio +import json +from asquare import client + + +async def list_categories(): + """List all categories in Square catalog""" + try: + print("\n" + "=" * 60) + print("SQUARE CATALOG CATEGORIES") + print("=" * 60 + "\n") + + cursor = None + page_count = 0 + total_categories = 0 + + while True: + page_count += 1 + print(f"Fetching page {page_count}...") + + search_params = { + "object_types": ["CATEGORY"], + "limit": 1000, + } + + if cursor: + search_params["cursor"] = cursor + + result = await client.catalog.search(**search_params) + result_json = json.loads(result.model_dump_json()) + + if not result_json.get("objects"): + if page_count == 1: + print("No categories found!") + break + + for obj in result_json["objects"]: + category_data = obj.get("category_data", {}) + category_id = obj.get("id") + category_name = category_data.get("name", "Unnamed") + + print(f"\nCategory: {category_name}") + print(f" ID: {category_id}") + + # Count items in this category + items_result = await client.catalog.search( + object_types=["ITEM"], + query={ + "exact_query": { + "attribute_name": "category_id", + "attribute_value": category_id, + } + }, + limit=1, + ) + items_json = json.loads(items_result.model_dump_json()) + item_count = len(items_json.get("objects", [])) + + print(f" Items: {item_count}+ items") + total_categories += 1 + + cursor = result_json.get("cursor") + if not cursor: + break + + print("\n" + "=" * 60) + print(f"Total categories found: {total_categories}") + print("=" * 60 + "\n") + + # Show current configured category + from get_sq_env import LEGO_CAT_ID + + print(f"Currently configured LEGO_CAT_ID: {LEGO_CAT_ID}") + print("\nUpdate .env file with the correct category ID if needed:") + print('SQUARE_LEGO_CAT_ID = "YOUR_CATEGORY_ID_HERE"') + print() + + except Exception as e: + print(f"Error listing categories: {e}") + import traceback + + traceback.print_exc() + + +if __name__ == "__main__": + asyncio.run(list_categories())