Skip to content

Commit fff5f82

Browse files
committed
complite reverse api
1 parent 35619a8 commit fff5f82

3 files changed

Lines changed: 42 additions & 18 deletions

File tree

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Реклама"""
22

3-
from typing import TYPE_CHECKING
3+
from typing import TYPE_CHECKING, Literal
44

55
from human_requests.abstraction import FetchResponse, HttpMethod
66

@@ -17,18 +17,18 @@ class ClassAdvertising:
1717
def __init__(self, parent: "PyaterochkaAPI"):
1818
self._parent: "PyaterochkaAPI" = parent
1919

20-
async def get_news(self, limit: int | None = None) -> FetchResponse:
21-
"""
22-
Asynchronously retrieves news from the Pyaterochka API.
23-
24-
Args:
25-
limit (int, optional): The maximum number of news items to retrieve. Defaults to None.
26-
27-
Returns:
28-
dict: A dictionary representing the news if the request is successful, error otherwise.
29-
"""
30-
url = f"{self._parent.MAIN_SITE_URL}/api/public/v1/news/"
31-
if limit and limit > 0:
32-
url += f"?limit={limit}"
33-
34-
return await self._parent._request(method=HttpMethod.GET, url=url)
20+
async def news(self,
21+
limit: int = 12,
22+
offset: int = 0):
23+
request_url = f"{self._parent.CATALOG_URL}/public/v1/news/?limit={limit}&offset={offset}"
24+
return await self._parent._request(method=HttpMethod.GET, url=request_url)
25+
26+
async def promo_offers(self,
27+
limit: int = 20,
28+
web_version: bool = True,
29+
type_offers: Literal["mainpage_promotion",
30+
"zooclub_promotion",
31+
"childrenclub_promotion",
32+
"barclub_promotion"] = "mainpage_promotion") -> FetchResponse:
33+
request_url = f"{self._parent.CATALOG_URL}/public/v1/promo-offers/?limit={limit}&web_version={str(web_version).lower()}&type={type_offers}"
34+
return await self._parent._request(method=HttpMethod.GET, url=request_url)

pyaterochka_api/endpoints/geolocation.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Геолокация"""
22

3-
from typing import TYPE_CHECKING
3+
from typing import TYPE_CHECKING, Optional
4+
import urllib
45

56
from human_requests.abstraction import FetchResponse, HttpMethod
67

@@ -32,3 +33,22 @@ async def find_store(self, longitude: float, latitude: float) -> FetchResponse:
3233

3334
request_url = f"{self._parent.CATALOG_URL}/orders/v1/orders/stores/?lon={longitude}&lat={latitude}"
3435
return await self._parent._request(method=HttpMethod.GET, url=request_url)
36+
37+
async def suggest(self, query: str) -> FetchResponse:
38+
"""Начинайте вводить адрес, он предложит точные варианты"""
39+
request_url = f"{self._parent.CATALOG_URL}/maps/suggest/?text={urllib.parse.quote(query)}"
40+
return await self._parent._request(method=HttpMethod.GET, url=request_url)
41+
42+
async def geocode(self,
43+
country: str = "Россия",
44+
city: str = "Москва",
45+
street: str = "проспект Мира",
46+
house: Optional[str] = None) -> FetchResponse:
47+
"""Возвращает геокод (геопозицию) на четкий запрос (используй suggest)"""
48+
tup = [country, city, street]
49+
if house:
50+
tup.append(house)
51+
string = urllib.parse.quote(", ".join(tup))
52+
53+
request_url = f"{self._parent.MAIN_SITE_URL}/api/maps/geocode/?geocode={string}"
54+
return await self._parent._request(method=HttpMethod.GET, url=request_url)

pyaterochka_api/manager.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from dataclasses import dataclass, field
55
from typing import Any
6+
import json
67

78
from camoufox.async_api import AsyncCamoufox
89
from human_requests import HumanBrowser, HumanContext, HumanPage
@@ -94,6 +95,10 @@ async def close(self):
9495
"""Закрыть HTTP-сессию и освободить ресурсы."""
9596
await self.session.close()
9697

98+
async def delivery_panel_store(self) -> dict:
99+
"""Текущий адрес доставке (при инициализации проставляется автоматически)"""
100+
return json.loads((await self.page.local_storage()).get("DeliveryPanelStore"))
101+
97102
async def _request(
98103
self,
99104
method: HttpMethod,
@@ -104,7 +109,6 @@ async def _request(
104109
"""Выполнить HTTP-запрос через внутреннюю сессию.
105110
106111
Единая точка входа для всех HTTP-запросов библиотеки.
107-
Добавляет к ответу объект Request для совместимости.
108112
109113
Args:
110114
method: HTTP метод (GET, POST, PUT, DELETE и т.д.)

0 commit comments

Comments
 (0)