1
1
import json
2
+ import logging
2
3
import re
3
4
4
5
# prefix components:
8
9
tee = "├── "
9
10
last = "└── "
10
11
12
+ LOGGER = logging .getLogger (__name__ )
13
+
11
14
IMAGE_SIZES = ["small" , "medium" , "regular" , "large" , "extra-large" ]
12
15
IMAGE_BASE_URL = "https://storefront-prod.nl.picnicinternational.com/static/images"
13
16
@@ -89,18 +92,21 @@ def _extract_search_results(raw_results, max_items: int = 10):
89
92
search_results = []
90
93
91
94
def find_articles (node ):
95
+ LOGGER .debug (f"Searching for products in { node } " )
92
96
if len (search_results ) >= max_items :
93
97
return
94
98
95
99
content = node .get ("content" , {})
96
100
if content .get ("type" ) == "SELLING_UNIT_TILE" and "sellingUnit" in content :
97
101
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 ))
99
104
sole_article_id = sole_article_ids [0 ] if sole_article_ids else None
100
105
result_entry = {
101
106
** selling_unit ,
102
107
"sole_article_id" : sole_article_id ,
103
108
}
109
+ LOGGER .debug (f"Found article { result_entry } " )
104
110
search_results .append (result_entry )
105
111
106
112
for child in node .get ("children" , []):
@@ -109,7 +115,11 @@ def find_articles(node):
109
115
if "child" in node :
110
116
find_articles (node .get ("child" ))
111
117
118
+ LOGGER .debug (f"Leaving extraction for node { node } " )
119
+
112
120
body = raw_results .get ("body" , {})
113
121
find_articles (body .get ("child" , {}))
114
122
123
+ LOGGER .debug (f"Found { len (search_results )} products after extraction" )
124
+
115
125
return [{"items" : search_results }]
0 commit comments