arfigyelo-api 0.1.0__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.
- arfigyelo_api/__init__.py +61 -0
- arfigyelo_api/_version.py +3 -0
- arfigyelo_api/cache.py +37 -0
- arfigyelo_api/client.py +785 -0
- arfigyelo_api/errors.py +51 -0
- arfigyelo_api/mapping.py +124 -0
- arfigyelo_api/models.py +198 -0
- arfigyelo_api/py.typed +0 -0
- arfigyelo_api-0.1.0.dist-info/METADATA +141 -0
- arfigyelo_api-0.1.0.dist-info/RECORD +12 -0
- arfigyelo_api-0.1.0.dist-info/WHEEL +4 -0
- arfigyelo_api-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""arfigyelo-api: Python client for the Árfigyelő price-comparison API."""
|
|
2
|
+
|
|
3
|
+
from ._version import __version__
|
|
4
|
+
from .cache import TTLCache
|
|
5
|
+
from .client import DEFAULT_BASE_URL, ArfigyeloClient, AsyncArfigyeloClient
|
|
6
|
+
from .errors import (
|
|
7
|
+
ArfigyeloApiError,
|
|
8
|
+
ArfigyeloConnectionError,
|
|
9
|
+
ArfigyeloError,
|
|
10
|
+
ArfigyeloUnexpectedResponseError,
|
|
11
|
+
ArfigyeloValidationError,
|
|
12
|
+
)
|
|
13
|
+
from .mapping import CategoryIndex, ChainIndex, ShopIndex
|
|
14
|
+
from .models import (
|
|
15
|
+
Category,
|
|
16
|
+
CategoryOrder,
|
|
17
|
+
Chain,
|
|
18
|
+
ChainPrices,
|
|
19
|
+
DetailChain,
|
|
20
|
+
DetailPrice,
|
|
21
|
+
ListPrice,
|
|
22
|
+
ProductDetail,
|
|
23
|
+
ProductPage,
|
|
24
|
+
ProductSummary,
|
|
25
|
+
SearchOrder,
|
|
26
|
+
Shop,
|
|
27
|
+
ShopLocation,
|
|
28
|
+
ShopPriceEntry,
|
|
29
|
+
ShopPrices,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"DEFAULT_BASE_URL",
|
|
34
|
+
"AsyncArfigyeloClient",
|
|
35
|
+
"ArfigyeloApiError",
|
|
36
|
+
"ArfigyeloClient",
|
|
37
|
+
"ArfigyeloConnectionError",
|
|
38
|
+
"ArfigyeloError",
|
|
39
|
+
"ArfigyeloUnexpectedResponseError",
|
|
40
|
+
"ArfigyeloValidationError",
|
|
41
|
+
"Category",
|
|
42
|
+
"CategoryIndex",
|
|
43
|
+
"CategoryOrder",
|
|
44
|
+
"Chain",
|
|
45
|
+
"ChainIndex",
|
|
46
|
+
"ChainPrices",
|
|
47
|
+
"DetailChain",
|
|
48
|
+
"DetailPrice",
|
|
49
|
+
"ListPrice",
|
|
50
|
+
"ProductDetail",
|
|
51
|
+
"ProductPage",
|
|
52
|
+
"ProductSummary",
|
|
53
|
+
"SearchOrder",
|
|
54
|
+
"Shop",
|
|
55
|
+
"ShopIndex",
|
|
56
|
+
"ShopLocation",
|
|
57
|
+
"ShopPriceEntry",
|
|
58
|
+
"ShopPrices",
|
|
59
|
+
"TTLCache",
|
|
60
|
+
"__version__",
|
|
61
|
+
]
|
arfigyelo_api/cache.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""In-memory TTL cache used for the structural indexes and optional price caching."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
from collections.abc import Callable, Hashable
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TTLCache[T]:
|
|
10
|
+
"""Key-value cache with time-based expiry.
|
|
11
|
+
|
|
12
|
+
``ttl=None`` means entries never expire. The clock is injectable for
|
|
13
|
+
tests. Entry values may be any type; a stored ``None`` is indistinguishable
|
|
14
|
+
from a miss (this package only caches model objects, never None).
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, ttl: float | None, *, clock: Callable[[], float] = time.monotonic) -> None:
|
|
18
|
+
self._ttl = ttl
|
|
19
|
+
self._clock = clock
|
|
20
|
+
self._entries: dict[Hashable, tuple[T, float]] = {}
|
|
21
|
+
|
|
22
|
+
def get(self, key: Hashable) -> T | None:
|
|
23
|
+
entry = self._entries.get(key)
|
|
24
|
+
if entry is None:
|
|
25
|
+
return None
|
|
26
|
+
value, deadline = entry
|
|
27
|
+
if self._ttl is not None and self._clock() >= deadline:
|
|
28
|
+
del self._entries[key]
|
|
29
|
+
return None
|
|
30
|
+
return value
|
|
31
|
+
|
|
32
|
+
def set(self, key: Hashable, value: T) -> None:
|
|
33
|
+
deadline = float("inf") if self._ttl is None else self._clock() + self._ttl
|
|
34
|
+
self._entries[key] = (value, deadline)
|
|
35
|
+
|
|
36
|
+
def clear(self) -> None:
|
|
37
|
+
self._entries.clear()
|