Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/python_picnic_api2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,30 @@
tree = "\n".join(_tree_generator(self.get_categories(depth=depth)))
print(tree)

def get_product_from_gtin(self, etan: str, maxRedirects: int = 5):

# Finds the product ID for a gtin/ean (barcode).
headers = (

Check warning on line 183 in src/python_picnic_api2/client.py

View check run for this annotation

Codecov / codecov/patch

src/python_picnic_api2/client.py#L183

Added line #L183 was not covered by tests
{
"x-picnic-agent": "30100;1.15.272-15295;",
"x-picnic-did": "3C417201548B2E3B",
}
)
url = "https://picnic.app/" + self._country_code.lower() + "/qr/gtin/" + etan
while maxRedirects > 0:
if url == "http://picnic.app/nl/link/store/storefront":

Check warning on line 191 in src/python_picnic_api2/client.py

View check run for this annotation

Codecov / codecov/patch

src/python_picnic_api2/client.py#L189-L191

Added lines #L189 - L191 were not covered by tests
# gtin unknown
return None
r = self.session.get(url, headers=headers, allow_redirects=False)
maxRedirects -= 1
if ";id=" in r.url:

Check warning on line 196 in src/python_picnic_api2/client.py

View check run for this annotation

Codecov / codecov/patch

src/python_picnic_api2/client.py#L193-L196

Added lines #L193 - L196 were not covered by tests
# found the product id
return r.url.split(";id=",1)[1]
if "Location" not in r.headers:

Check warning on line 199 in src/python_picnic_api2/client.py

View check run for this annotation

Codecov / codecov/patch

src/python_picnic_api2/client.py#L198-L199

Added lines #L198 - L199 were not covered by tests
# product id not found but also no futher redirect
return None
url = r.headers["Location"]
return None

Check warning on line 203 in src/python_picnic_api2/client.py

View check run for this annotation

Codecov / codecov/patch

src/python_picnic_api2/client.py#L201-L203

Added lines #L201 - L203 were not covered by tests


__all__ = ["PicnicAPI"]