File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -177,5 +177,30 @@ def print_categories(self, depth: int = 0):
177
177
tree = "\n " .join (_tree_generator (self .get_categories (depth = depth )))
178
178
print (tree )
179
179
180
+ def get_product_from_gtin (self , etan : str , maxRedirects : int = 5 ):
181
+
182
+ # Finds the product ID for a gtin/ean (barcode).
183
+ headers = (
184
+ {
185
+ "x-picnic-agent" : "30100;1.15.272-15295;" ,
186
+ "x-picnic-did" : "3C417201548B2E3B" ,
187
+ }
188
+ )
189
+ url = "https://picnic.app/" + self ._country_code .lower () + "/qr/gtin/" + etan
190
+ while maxRedirects > 0 :
191
+ if url == "http://picnic.app/nl/link/store/storefront" :
192
+ # gtin unknown
193
+ return None
194
+ r = self .session .get (url , headers = headers , allow_redirects = False )
195
+ maxRedirects -= 1
196
+ if ";id=" in r .url :
197
+ # found the product id
198
+ return r .url .split (";id=" ,1 )[1 ]
199
+ if "Location" not in r .headers :
200
+ # product id not found but also no futher redirect
201
+ return None
202
+ url = r .headers ["Location" ]
203
+ return None
204
+
180
205
181
206
__all__ = ["PicnicAPI" ]
You can’t perform that action at this time.
0 commit comments