11"""Работа с каталогом"""
22
3- from typing import TYPE_CHECKING
4-
3+ from typing import TYPE_CHECKING , Optional
4+ import urllib . parse
55from human_requests .abstraction import FetchResponse , HttpMethod
66
7- from ..enums import PurchaseMode
7+ from ..enums import PurchaseMode , Sorting
88if TYPE_CHECKING :
99 from ..manager import PyaterochkaAPI
1010
@@ -47,10 +47,34 @@ async def tree(self,
4747 request_url = f"{ self ._parent .CATALOG_URL } /catalog/v2/stores/{ sap_code_store_id } /categories?mode={ mode .value } &include_restrict={ include_restrict } &include_subcategories={ 1 if subcategories else 0 } "
4848 return await self ._parent ._request (method = HttpMethod .GET , url = request_url )
4949
50+ async def tree_extended (self ,
51+ sap_code_store_id : str ,
52+ category_id : str ,
53+ include_restrict : bool = True ,
54+ mode : PurchaseMode = PurchaseMode .STORE ) -> FetchResponse :
55+ """Расширенное представление категории и её подкатегорий."""
56+ request_url = f"{ self ._parent .CATALOG_URL } /api/catalog/v2/stores/{ sap_code_store_id } /categories/{ category_id } /extended?mode={ mode .value } &include_restrict={ str (include_restrict ).lower ()} "
57+ return await self ._parent ._request (method = HttpMethod .GET , url = request_url )
58+
59+ async def search (self ,
60+ sap_code_store_id : str ,
61+ query : str ,
62+ include_restrict : bool = True ,
63+ mode : PurchaseMode = PurchaseMode .STORE ,
64+ limit : int = 12 ) -> FetchResponse :
65+ """Поиск по товарам И категориям."""
66+ q = urllib .parse .quote (query )
67+ request_url = f"{ self ._parent .CATALOG_URL } /api/catalog/v3/stores/{ sap_code_store_id } /search?mode={ mode .value } &include_restrict={ str (include_restrict ).lower ()} &q={ q } &limit={ limit } "
68+ return await self ._parent ._request (method = HttpMethod .GET , url = request_url )
69+
5070 async def products_list (
5171 self ,
5272 category_id : str ,
5373 sap_code_store_id : str ,
74+ price_min : Optional [int ] = None ,
75+ price_max : Optional [int ] = None ,
76+ brands : list [str ] = [],
77+ include_restrict : bool = True ,
5478 mode : PurchaseMode = PurchaseMode .STORE ,
5579 limit : int = 30
5680 ) -> FetchResponse :
@@ -74,7 +98,27 @@ async def products_list(
7498 if limit < 1 or limit >= 500 :
7599 raise ValueError ("Limit must be between 1 and 499" )
76100
77- request_url = f"{ self ._parent .CATALOG_URL } /catalog/v2/stores/{ sap_code_store_id } /categories/{ category_id } /products?mode={ mode .value } &limit={ limit } "
101+ request_url = f"{ self ._parent .CATALOG_URL } /catalog/v2/stores/{ sap_code_store_id } /categories/{ category_id } /products?mode={ mode .value } &limit={ limit } &include_restrict={ str (include_restrict ).lower ()} "
102+ if price_min :
103+ request_url += "&price_min=" + str (price_min )
104+ if price_max :
105+ request_url += "&price_max=" + str (price_max )
106+ if len (brands ) > 0 :
107+ encoded_brands = [f'brands={ urllib .parse .quote (brand )} ' for brand in brands ]
108+ request_url += "&" + '&&' .join (encoded_brands )
109+
110+ return await self ._parent ._request (method = HttpMethod .GET , url = request_url )
111+
112+ async def products_line (
113+ self ,
114+ category_id : str ,
115+ sap_code_store_id : str ,
116+ include_restrict : bool = True ,
117+ mode : PurchaseMode = PurchaseMode .STORE ,
118+ order_by : Sorting = Sorting .POPULARITY
119+ ) -> FetchResponse :
120+ """Рекомендованные товары \" что интересного?\" ."""
121+ request_url = f"https://5d.5ka.ru/api/catalog/v1/stores/{ sap_code_store_id } /categories/{ category_id } /products_line?mode={ mode .value } &include_restrict={ str (include_restrict ).lower ()} &order_by={ order_by .value } "
78122 return await self ._parent ._request (method = HttpMethod .GET , url = request_url )
79123
80124
0 commit comments