python-picnic-api2 2.0.2__py3-none-any.whl → 2.0.3__py3-none-any.whl
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/__init__.py +1 -1
- python_picnic_api2/client.py +21 -8
- {python_picnic_api2-2.0.2.dist-info → python_picnic_api2-2.0.3.dist-info}/METADATA +7 -1
- {python_picnic_api2-2.0.2.dist-info → python_picnic_api2-2.0.3.dist-info}/RECORD +6 -6
- {python_picnic_api2-2.0.2.dist-info → python_picnic_api2-2.0.3.dist-info}/WHEEL +0 -0
- {python_picnic_api2-2.0.2.dist-info → python_picnic_api2-2.0.3.dist-info}/licenses/LICENSE.md +0 -0
python_picnic_api2/__init__.py
CHANGED
python_picnic_api2/client.py
CHANGED
|
@@ -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,7 @@ 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
|
-
"x-picnic-agent": "30100;1.206.1-#15408",
|
|
31
|
-
"x-picnic-did": "598F770380CA54B6",
|
|
32
|
-
}
|
|
30
|
+
_PICNIC_AGENT = "30100;1.252.0-#15626;"
|
|
33
31
|
|
|
34
32
|
|
|
35
33
|
class PicnicAPI:
|
|
@@ -39,18 +37,31 @@ class PicnicAPI:
|
|
|
39
37
|
password: str = None,
|
|
40
38
|
country_code: str = DEFAULT_COUNTRY_CODE,
|
|
41
39
|
auth_token: str = None,
|
|
40
|
+
device_id: str | None = None,
|
|
42
41
|
):
|
|
43
42
|
self._country_code = country_code
|
|
44
43
|
self._base_url = _url_generator(
|
|
45
44
|
DEFAULT_URL, self._country_code, DEFAULT_API_VERSION
|
|
46
45
|
)
|
|
47
46
|
|
|
47
|
+
# Picnic seems to start blocking static device ids
|
|
48
|
+
self._device_id = device_id or secrets.token_hex(8).upper()
|
|
49
|
+
self._picnic_headers = {
|
|
50
|
+
"x-picnic-agent": _PICNIC_AGENT,
|
|
51
|
+
"x-picnic-did": self._device_id,
|
|
52
|
+
}
|
|
53
|
+
|
|
48
54
|
self.session = PicnicAPISession(auth_token=auth_token)
|
|
49
55
|
|
|
50
56
|
# Login if not authenticated
|
|
51
57
|
if not self.session.authenticated and username and password:
|
|
52
58
|
self.login(username, password)
|
|
53
59
|
|
|
60
|
+
@property
|
|
61
|
+
def device_id(self) -> str:
|
|
62
|
+
"""The ``x-picnic-did`` value sent to Picnic; persist it to reuse it."""
|
|
63
|
+
return self._device_id
|
|
64
|
+
|
|
54
65
|
@staticmethod
|
|
55
66
|
def _parse_json(response, url: str):
|
|
56
67
|
"""Decode a response body, raising a descriptive error if it is not JSON.
|
|
@@ -74,7 +85,7 @@ class PicnicAPI:
|
|
|
74
85
|
url = self._base_url + path
|
|
75
86
|
|
|
76
87
|
# Make the request, add special picnic headers if needed
|
|
77
|
-
headers =
|
|
88
|
+
headers = self._picnic_headers if add_picnic_headers else None
|
|
78
89
|
response = self.session.get(url, headers=headers)
|
|
79
90
|
body = self._parse_json(response, url)
|
|
80
91
|
|
|
@@ -89,7 +100,7 @@ class PicnicAPI:
|
|
|
89
100
|
url = (base_url_override if base_url_override else self._base_url) + path
|
|
90
101
|
kwargs = {"json": data}
|
|
91
102
|
if add_picnic_headers:
|
|
92
|
-
kwargs["headers"] =
|
|
103
|
+
kwargs["headers"] = self._picnic_headers
|
|
93
104
|
response = self.session.post(url, **kwargs)
|
|
94
105
|
body = self._parse_json(response, url)
|
|
95
106
|
|
|
@@ -136,7 +147,7 @@ class PicnicAPI:
|
|
|
136
147
|
def _post_2fa(self, path: str, data=None):
|
|
137
148
|
"""POST for 2FA endpoints that may return empty (204) or JSON error bodies."""
|
|
138
149
|
url = self._base_url + path
|
|
139
|
-
response = self.session.post(url, json=data, headers=
|
|
150
|
+
response = self.session.post(url, json=data, headers=self._picnic_headers)
|
|
140
151
|
|
|
141
152
|
if response.status_code == 204 or not response.content:
|
|
142
153
|
return None
|
|
@@ -315,7 +326,9 @@ class PicnicAPI:
|
|
|
315
326
|
if url == "http://picnic.app/nl/link/store/storefront":
|
|
316
327
|
# gtin unknown
|
|
317
328
|
return None
|
|
318
|
-
r = self.session.get(
|
|
329
|
+
r = self.session.get(
|
|
330
|
+
url, headers=self._picnic_headers, allow_redirects=False
|
|
331
|
+
)
|
|
319
332
|
maxRedirects -= 1
|
|
320
333
|
if ";id=" in r.url:
|
|
321
334
|
# found the article id
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: python-picnic-api2
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.3
|
|
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:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
python_picnic_api2/__init__.py,sha256=
|
|
2
|
-
python_picnic_api2/client.py,sha256=
|
|
1
|
+
python_picnic_api2/__init__.py,sha256=gNGbMpwpu2-H06qbgZ6AYcNAsrvHbihX2fu7vUtQWDk,975
|
|
2
|
+
python_picnic_api2/client.py,sha256=C1Vai_PePut-KQ4xh4LwpSZV-HPyLDn8XqAgZhjmNhw,12306
|
|
3
3
|
python_picnic_api2/exceptions.py,sha256=q3ERqBze8rMoNjX0QcRfinCWhExSdob6AFs4l23iSyQ,1973
|
|
4
4
|
python_picnic_api2/helper.py,sha256=CUoxRu2SZnHE-8azyfm7MUJ_vBA7ifVkHK-IUgUKuRM,971
|
|
5
5
|
python_picnic_api2/session.py,sha256=2nhlyJ2MXR1yHQRxw85B-KXF4zt8L5__KrI-T_VvURg,2388
|
|
@@ -13,7 +13,7 @@ python_picnic_api2/models/delivery.py,sha256=i29cw3E_To3azBGtYKvYkKolRpWJypWxPql
|
|
|
13
13
|
python_picnic_api2/models/pml.py,sha256=1NAygk1u2SKBo-QwWMoeuZ4ixTJdDLHdnM7blYdgplM,5290
|
|
14
14
|
python_picnic_api2/models/search.py,sha256=kGJVXKUml2wFfDyap000inhe5udGO_EssxVji0FJ1f4,2150
|
|
15
15
|
python_picnic_api2/models/user.py,sha256=Q0qmnhYacCCx93UO_OrpHLdiE4VtCWsunRhJUmxgruY,1662
|
|
16
|
-
python_picnic_api2-2.0.
|
|
17
|
-
python_picnic_api2-2.0.
|
|
18
|
-
python_picnic_api2-2.0.
|
|
19
|
-
python_picnic_api2-2.0.
|
|
16
|
+
python_picnic_api2-2.0.3.dist-info/METADATA,sha256=_4BowMS_7hzF-1SakCTv_N72IncHZxKVsgHChQ8Sv7s,8938
|
|
17
|
+
python_picnic_api2-2.0.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
18
|
+
python_picnic_api2-2.0.3.dist-info/licenses/LICENSE.md,sha256=CUvt2ilcBwKAfRAnoA4RNPTLcdUj3En21LPK9YkFMGg,11358
|
|
19
|
+
python_picnic_api2-2.0.3.dist-info/RECORD,,
|
|
File without changes
|
{python_picnic_api2-2.0.2.dist-info → python_picnic_api2-2.0.3.dist-info}/licenses/LICENSE.md
RENAMED
|
File without changes
|