diff --git a/src/python_picnic_api2/helper.py b/src/python_picnic_api2/helper.py index 5954fe9..9bd08cb 100644 --- a/src/python_picnic_api2/helper.py +++ b/src/python_picnic_api2/helper.py @@ -1,4 +1,5 @@ import json +import logging import re # prefix components: @@ -8,6 +9,8 @@ tee = "├── " last = "└── " +LOGGER = logging.getLogger(__name__) + IMAGE_SIZES = ["small", "medium", "regular", "large", "extra-large"] IMAGE_BASE_URL = "https://storefront-prod.nl.picnicinternational.com/static/images" @@ -88,6 +91,8 @@ def _extract_search_results(raw_results, max_items: int = 10): search""" search_results = [] + LOGGER.debug(f"Extracting search results from {raw_results}") + def find_articles(node): if len(search_results) >= max_items: return @@ -101,6 +106,7 @@ def find_articles(node): **selling_unit, "sole_article_id": sole_article_id, } + LOGGER.debug(f"Found article {result_entry}") search_results.append(result_entry) for child in node.get("children", []): @@ -112,4 +118,6 @@ def find_articles(node): body = raw_results.get("body", {}) find_articles(body.get("child", {})) + LOGGER.debug(f"Found {len(search_results)}/{max_items} products after extraction") + return [{"items": search_results}]