Skip to content

Commit 67b9033

Browse files
committed
Add logging to search extraction
1 parent e4e2010 commit 67b9033

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/python_picnic_api2/helper.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import logging
23
import re
34

45
# prefix components:
@@ -8,6 +9,8 @@
89
tee = "├── "
910
last = "└── "
1011

12+
LOGGER = logging.getLogger(__name__)
13+
1114
IMAGE_SIZES = ["small", "medium", "regular", "large", "extra-large"]
1215
IMAGE_BASE_URL = "https://storefront-prod.nl.picnicinternational.com/static/images"
1316

@@ -89,18 +92,21 @@ def _extract_search_results(raw_results, max_items: int = 10):
8992
search_results = []
9093

9194
def find_articles(node):
95+
LOGGER.debug(f"Searching for products in {node}")
9296
if len(search_results) >= max_items:
9397
return
9498

9599
content = node.get("content", {})
96100
if content.get("type") == "SELLING_UNIT_TILE" and "sellingUnit" in content:
97101
selling_unit = content["sellingUnit"]
98-
sole_article_ids = SOLE_ARTICLE_ID_PATTERN.findall(json.dumps(node))
102+
sole_article_ids = SOLE_ARTICLE_ID_PATTERN.findall(
103+
json.dumps(node))
99104
sole_article_id = sole_article_ids[0] if sole_article_ids else None
100105
result_entry = {
101106
**selling_unit,
102107
"sole_article_id": sole_article_id,
103108
}
109+
LOGGER.debug(f"Found article {result_entry}")
104110
search_results.append(result_entry)
105111

106112
for child in node.get("children", []):
@@ -109,7 +115,11 @@ def find_articles(node):
109115
if "child" in node:
110116
find_articles(node.get("child"))
111117

118+
LOGGER.debug(f"Leaving extraction for node {node}")
119+
112120
body = raw_results.get("body", {})
113121
find_articles(body.get("child", {}))
114122

123+
LOGGER.debug(f"Found {len(search_results)} products after extraction")
124+
115125
return [{"items": search_results}]

0 commit comments

Comments
 (0)