python-picnic-api2 2.0.2__tar.gz → 2.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/PKG-INFO +7 -1
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/README.md +6 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/pyproject.toml +1 -1
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/__init__.py +1 -1
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/client.py +24 -8
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/test_client.py +23 -3
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/uv.lock +1 -1
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/.devcontainer/devcontainer.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/.env.example +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/.envrc +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/.github/dependabot.yml +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/.github/release.yml +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/.github/workflows/ci.yaml +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/.github/workflows/it.yaml +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/.github/workflows/release.yml +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/.gitignore +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/LICENSE.md +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/codecov.yml +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/flake.lock +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/flake.nix +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/integration_tests/__init__.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/integration_tests/test_client.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/integration_tests/test_helper.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/integration_tests/test_session.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/scripts/capture_fixtures.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/exceptions.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/helper.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/__init__.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/article.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/base.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/cart.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/category.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/common.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/delivery.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/pml.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/search.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/user.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/session.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/__init__.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/cart_de.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/category_page_nl.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/current_deliveries_de.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/delivery_de.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/delivery_slots_de.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/product_details_bundle_de.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/product_details_multipack_nl.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/product_details_page_de.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/product_details_page_nl.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/search_page_de.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/search_page_nl.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/user_de.json +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/test_fixtures.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/test_models.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/test_pml.py +0 -0
- {python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/test_session.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: python-picnic-api2
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.4
|
|
4
4
|
Project-URL: homepage, https://github.com/codesalatdev/python-picnic-api
|
|
5
5
|
Project-URL: repository, https://github.com/codesalatdev/python-picnic-api
|
|
6
6
|
Author-email: Mike Brink <mjh.brink@icloud.com>, CodeSalat <pypi@codesalat.dev>
|
|
@@ -47,6 +47,12 @@ picnic = PicnicAPI(username='username', password='password', country_code="NL")
|
|
|
47
47
|
|
|
48
48
|
The country_code parameter defaults to `NL`, but you have to change it if you live in a different country than the Netherlands (ISO 3166-1 Alpha-2). This obviously only works for countries that picnic services.
|
|
49
49
|
|
|
50
|
+
Picnic identifies each app install by a device ID (the `x-picnic-did` header). `PicnicAPI` generates a random one per instance. To keep the same ID across restarts, store `picnic.device_id` and pass it back in:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
picnic = PicnicAPI(auth_token=token, device_id=stored_device_id)
|
|
54
|
+
```
|
|
55
|
+
|
|
50
56
|
### Two-factor authentication (2FA)
|
|
51
57
|
|
|
52
58
|
For new logins, Picnic may require two-factor authentication. When 2FA is required, logging in raises a `Picnic2FARequired` exception. You then need to request a code and verify it:
|
|
@@ -32,6 +32,12 @@ picnic = PicnicAPI(username='username', password='password', country_code="NL")
|
|
|
32
32
|
|
|
33
33
|
The country_code parameter defaults to `NL`, but you have to change it if you live in a different country than the Netherlands (ISO 3166-1 Alpha-2). This obviously only works for countries that picnic services.
|
|
34
34
|
|
|
35
|
+
Picnic identifies each app install by a device ID (the `x-picnic-did` header). `PicnicAPI` generates a random one per instance. To keep the same ID across restarts, store `picnic.device_id` and pass it back in:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
picnic = PicnicAPI(auth_token=token, device_id=stored_device_id)
|
|
39
|
+
```
|
|
40
|
+
|
|
35
41
|
### Two-factor authentication (2FA)
|
|
36
42
|
|
|
37
43
|
For new logins, Picnic may require two-factor authentication. When 2FA is required, logging in raises a `Picnic2FARequired` exception. You then need to request a code and verify it:
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import secrets
|
|
1
2
|
from hashlib import md5
|
|
2
3
|
from urllib.parse import quote
|
|
3
4
|
|
|
@@ -26,10 +27,10 @@ from .session import (
|
|
|
26
27
|
DEFAULT_URL = "https://storefront-prod.{}.picnicinternational.com/api/{}"
|
|
27
28
|
DEFAULT_COUNTRY_CODE = "NL"
|
|
28
29
|
DEFAULT_API_VERSION = "15"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
# Pinned below app 1.224: newer agents get the /pages/ endpoints as a
|
|
31
|
+
# {"layout", "script"} wrapper (1.224-1.246) or React Server Components (1.247+),
|
|
32
|
+
# which the PML parsers do not handle.
|
|
33
|
+
_PICNIC_AGENT = "30100;1.206.1-#15408"
|
|
33
34
|
|
|
34
35
|
|
|
35
36
|
class PicnicAPI:
|
|
@@ -39,18 +40,31 @@ class PicnicAPI:
|
|
|
39
40
|
password: str = None,
|
|
40
41
|
country_code: str = DEFAULT_COUNTRY_CODE,
|
|
41
42
|
auth_token: str = None,
|
|
43
|
+
device_id: str | None = None,
|
|
42
44
|
):
|
|
43
45
|
self._country_code = country_code
|
|
44
46
|
self._base_url = _url_generator(
|
|
45
47
|
DEFAULT_URL, self._country_code, DEFAULT_API_VERSION
|
|
46
48
|
)
|
|
47
49
|
|
|
50
|
+
# Picnic seems to start blocking static device ids
|
|
51
|
+
self._device_id = device_id or secrets.token_hex(8).upper()
|
|
52
|
+
self._picnic_headers = {
|
|
53
|
+
"x-picnic-agent": _PICNIC_AGENT,
|
|
54
|
+
"x-picnic-did": self._device_id,
|
|
55
|
+
}
|
|
56
|
+
|
|
48
57
|
self.session = PicnicAPISession(auth_token=auth_token)
|
|
49
58
|
|
|
50
59
|
# Login if not authenticated
|
|
51
60
|
if not self.session.authenticated and username and password:
|
|
52
61
|
self.login(username, password)
|
|
53
62
|
|
|
63
|
+
@property
|
|
64
|
+
def device_id(self) -> str:
|
|
65
|
+
"""The ``x-picnic-did`` value sent to Picnic; persist it to reuse it."""
|
|
66
|
+
return self._device_id
|
|
67
|
+
|
|
54
68
|
@staticmethod
|
|
55
69
|
def _parse_json(response, url: str):
|
|
56
70
|
"""Decode a response body, raising a descriptive error if it is not JSON.
|
|
@@ -74,7 +88,7 @@ class PicnicAPI:
|
|
|
74
88
|
url = self._base_url + path
|
|
75
89
|
|
|
76
90
|
# Make the request, add special picnic headers if needed
|
|
77
|
-
headers =
|
|
91
|
+
headers = self._picnic_headers if add_picnic_headers else None
|
|
78
92
|
response = self.session.get(url, headers=headers)
|
|
79
93
|
body = self._parse_json(response, url)
|
|
80
94
|
|
|
@@ -89,7 +103,7 @@ class PicnicAPI:
|
|
|
89
103
|
url = (base_url_override if base_url_override else self._base_url) + path
|
|
90
104
|
kwargs = {"json": data}
|
|
91
105
|
if add_picnic_headers:
|
|
92
|
-
kwargs["headers"] =
|
|
106
|
+
kwargs["headers"] = self._picnic_headers
|
|
93
107
|
response = self.session.post(url, **kwargs)
|
|
94
108
|
body = self._parse_json(response, url)
|
|
95
109
|
|
|
@@ -136,7 +150,7 @@ class PicnicAPI:
|
|
|
136
150
|
def _post_2fa(self, path: str, data=None):
|
|
137
151
|
"""POST for 2FA endpoints that may return empty (204) or JSON error bodies."""
|
|
138
152
|
url = self._base_url + path
|
|
139
|
-
response = self.session.post(url, json=data, headers=
|
|
153
|
+
response = self.session.post(url, json=data, headers=self._picnic_headers)
|
|
140
154
|
|
|
141
155
|
if response.status_code == 204 or not response.content:
|
|
142
156
|
return None
|
|
@@ -315,7 +329,9 @@ class PicnicAPI:
|
|
|
315
329
|
if url == "http://picnic.app/nl/link/store/storefront":
|
|
316
330
|
# gtin unknown
|
|
317
331
|
return None
|
|
318
|
-
r = self.session.get(
|
|
332
|
+
r = self.session.get(
|
|
333
|
+
url, headers=self._picnic_headers, allow_redirects=False
|
|
334
|
+
)
|
|
319
335
|
maxRedirects -= 1
|
|
320
336
|
if ";id=" in r.url:
|
|
321
337
|
# found the article id
|
|
@@ -11,9 +11,10 @@ from python_picnic_api2.session import (
|
|
|
11
11
|
PicnicAuthError,
|
|
12
12
|
)
|
|
13
13
|
|
|
14
|
+
DEVICE_ID = "0123456789ABCDEF"
|
|
14
15
|
PICNIC_HEADERS = {
|
|
15
16
|
"x-picnic-agent": "30100;1.206.1-#15408",
|
|
16
|
-
"x-picnic-did":
|
|
17
|
+
"x-picnic-did": DEVICE_ID,
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
|
|
@@ -37,7 +38,9 @@ class TestClient(unittest.TestCase):
|
|
|
37
38
|
self.session_patcher = patch(
|
|
38
39
|
"python_picnic_api2.client.PicnicAPISession")
|
|
39
40
|
self.session_mock = self.session_patcher.start()
|
|
40
|
-
self.client = PicnicAPI(
|
|
41
|
+
self.client = PicnicAPI(
|
|
42
|
+
username="test@test.nl", password="test", device_id=DEVICE_ID
|
|
43
|
+
)
|
|
41
44
|
self.expected_base_url = DEFAULT_URL.format("nl", "15")
|
|
42
45
|
|
|
43
46
|
def tearDown(self) -> None:
|
|
@@ -45,7 +48,7 @@ class TestClient(unittest.TestCase):
|
|
|
45
48
|
|
|
46
49
|
def test_login_credentials(self):
|
|
47
50
|
self.session_mock().authenticated = False
|
|
48
|
-
PicnicAPI(username="test@test.nl", password="test")
|
|
51
|
+
PicnicAPI(username="test@test.nl", password="test", device_id=DEVICE_ID)
|
|
49
52
|
self.session_mock().post.assert_called_with(
|
|
50
53
|
self.expected_base_url + "/user/login",
|
|
51
54
|
json={
|
|
@@ -56,6 +59,23 @@ class TestClient(unittest.TestCase):
|
|
|
56
59
|
headers=PICNIC_HEADERS,
|
|
57
60
|
)
|
|
58
61
|
|
|
62
|
+
def test_device_id_generated_per_client(self):
|
|
63
|
+
first, second = PicnicAPI(), PicnicAPI()
|
|
64
|
+
self.assertRegex(first.device_id, r"^[0-9A-F]{16}$")
|
|
65
|
+
self.assertNotEqual(first.device_id, second.device_id)
|
|
66
|
+
|
|
67
|
+
self.session_mock().get.return_value = self.MockResponse(
|
|
68
|
+
{"type": "ORDER", "id": "shopping_cart"}, 200
|
|
69
|
+
)
|
|
70
|
+
first.get_cart()
|
|
71
|
+
self.session_mock().get.assert_called_with(
|
|
72
|
+
self.expected_base_url + "/cart",
|
|
73
|
+
headers={
|
|
74
|
+
"x-picnic-agent": PICNIC_HEADERS["x-picnic-agent"],
|
|
75
|
+
"x-picnic-did": first.device_id,
|
|
76
|
+
},
|
|
77
|
+
)
|
|
78
|
+
|
|
59
79
|
def test_login_auth_token(self):
|
|
60
80
|
self.session_mock().authenticated = True
|
|
61
81
|
PicnicAPI(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/__init__.py
RENAMED
|
File without changes
|
{python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/article.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/category.py
RENAMED
|
File without changes
|
{python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/common.py
RENAMED
|
File without changes
|
{python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/delivery.py
RENAMED
|
File without changes
|
|
File without changes
|
{python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/src/python_picnic_api2/models/search.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/current_deliveries_de.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/product_details_bundle_de.json
RENAMED
|
File without changes
|
|
File without changes
|
{python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/product_details_page_de.json
RENAMED
|
File without changes
|
{python_picnic_api2-2.0.2 → python_picnic_api2-2.0.4}/tests/fixtures/product_details_page_nl.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|