11import json
2+ import logging
23import re
34
45# prefix components:
89tee = "├── "
910last = "└── "
1011
12+ LOGGER = logging .getLogger (__name__ )
13+
1114IMAGE_SIZES = ["small" , "medium" , "regular" , "large" , "extra-large" ]
1215IMAGE_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