From 67b90338b8e877778d872ee11857a94a9e2a8e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20Gro=C3=9F?= Date: Sun, 23 Mar 2025 21:27:38 +0000 Subject: [PATCH 1/2] Add logging to search extraction --- src/python_picnic_api2/helper.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/python_picnic_api2/helper.py b/src/python_picnic_api2/helper.py index 5954fe9..ab3c120 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" @@ -89,18 +92,21 @@ def _extract_search_results(raw_results, max_items: int = 10): search_results = [] def find_articles(node): + LOGGER.debug(f"Searching for products in {node}") if len(search_results) >= max_items: return content = node.get("content", {}) if content.get("type") == "SELLING_UNIT_TILE" and "sellingUnit" in content: selling_unit = content["sellingUnit"] - sole_article_ids = SOLE_ARTICLE_ID_PATTERN.findall(json.dumps(node)) + sole_article_ids = SOLE_ARTICLE_ID_PATTERN.findall( + json.dumps(node)) sole_article_id = sole_article_ids[0] if sole_article_ids else None result_entry = { **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", []): @@ -109,7 +115,11 @@ def find_articles(node): if "child" in node: find_articles(node.get("child")) + LOGGER.debug(f"Leaving extraction for node {node}") + body = raw_results.get("body", {}) find_articles(body.get("child", {})) + LOGGER.debug(f"Found {len(search_results)} products after extraction") + return [{"items": search_results}] From 2714db9927638abfa596e14d83be22f7b196b08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20Gro=C3=9F?= Date: Tue, 25 Mar 2025 09:46:45 +0000 Subject: [PATCH 2/2] Reduce debug logging for product search --- src/python_picnic_api2/helper.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/python_picnic_api2/helper.py b/src/python_picnic_api2/helper.py index ab3c120..9bd08cb 100644 --- a/src/python_picnic_api2/helper.py +++ b/src/python_picnic_api2/helper.py @@ -91,16 +91,16 @@ 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): - LOGGER.debug(f"Searching for products in {node}") if len(search_results) >= max_items: return content = node.get("content", {}) if content.get("type") == "SELLING_UNIT_TILE" and "sellingUnit" in content: selling_unit = content["sellingUnit"] - sole_article_ids = SOLE_ARTICLE_ID_PATTERN.findall( - json.dumps(node)) + sole_article_ids = SOLE_ARTICLE_ID_PATTERN.findall(json.dumps(node)) sole_article_id = sole_article_ids[0] if sole_article_ids else None result_entry = { **selling_unit, @@ -115,11 +115,9 @@ def find_articles(node): if "child" in node: find_articles(node.get("child")) - LOGGER.debug(f"Leaving extraction for node {node}") - body = raw_results.get("body", {}) find_articles(body.get("child", {})) - LOGGER.debug(f"Found {len(search_results)} products after extraction") + LOGGER.debug(f"Found {len(search_results)}/{max_items} products after extraction") return [{"items": search_results}]