@@ -8,41 +8,53 @@ Quick Start
88
99 .. code-block :: python
1010
11- from chizhik_api import ChizhikAPI
11+ import asyncio
12+ from fixprice_api import FixPriceAPI, CatalogSort
13+ from PIL import Image
14+
1215
1316 async def main ():
14- # RUS: Использование проксирования опционально. Вы можете создать несколько агентов с разными прокси для ускорения парса.
15- # ENG: Proxy usage is optional. You can create multiple agents with different proxies for faster parsing.
16- async with ChizhikAPI(proxy = " user:password@host:port" , headless = False ) as API :
17- # RUS: Выводит активные предложения магазина
18- # ENG: Outputs active offers of the store
19- print (f " Active offers output: { (await API .Advertising.active_inout()).json()!s:.100s } ... \n " )
20-
21- # RUS: Выводит список городов соответствующих поисковому запросу (только на русском языке)
22- # ENG: Outputs a list of cities corresponding to the search query (only in Russian language)
23- city_list = (await API .Geolocation.cities_list(search_name = ' ар' , page = 1 )).json()
24- print (f " Cities list output: { city_list!s:.100s } ... \n " )
25- # Счет страниц с единицы / index starts from 1
26-
27- # RUS: Выводит список всех категорий на сайте
28- # ENG: Outputs a list of all categories on the site
29- catalog = (await API .Catalog.tree()).json()
30- print (f " Categories list output: { catalog!s:.100s } ... \n " )
31-
32- # RUS: Выводит список всех товаров выбранной категории (ограничение 100 элементов, если превышает - запрашивайте через дополнительные страницы)
33- # ENG: Outputs a list of all items in the selected category (limiting to 100 elements, if exceeds - request through additional pages)
34- items = (await API .Catalog.products_list(category_id = catalog[0 ][' id' ], page = 1 )).json()
35- print (f " Items list output: { items!s:.100s } ... \n " )
36- # Счет страниц с единицы / index starts from 1
37-
38- # RUS: Сохраняем изображение с сервера (в принципе, сервер отдал бы их и без обертки моего объекта, но лучше максимально претворяться обычным пользователем)
39- # ENG: Saving an image from the server (in fact, the server gave them and without wrapping my object, but better to be as a regular user)
40- image = await API .General.download_image(items[' items' ][0 ][' images' ][0 ][' image' ])
41- with open (image.name, ' wb' ) as f:
42- f.write(image.read())
17+ async with FixPriceAPI() as api:
18+ # 1. Получаем дерево категорий
19+ tree_data = (await api.Catalog.tree()).json()
20+ first_alias = tree_data[next (iter (tree_data))][" alias" ]
21+ print (f " Первая категория: { first_alias} " )
4322
44- import asyncio
45- asyncio.run(main())
23+ # 2. Список товаров в категории
24+ products = (
25+ await api.Catalog.products_list(
26+ category_alias = first_alias,
27+ page = 1 ,
28+ limit = 24 ,
29+ sort = CatalogSort.POPULARITY ,
30+ )
31+ ).json()
32+ first_product_id = products[0 ][" id" ]
33+ first_product_url = products[0 ][" url" ]
34+ print (f " Первый товар: { products[0 ][' title' ]!s:.60s } ( { first_product_id} ) " )
35+
36+ # 3. Геолокация (влияет на каталог и баланс)
37+ cities = (await api.Geolocation.cities_list(country_id = 2 )).json() # Россия
38+ api.city_id = cities[0 ][" id" ]
39+ print (f " Текущий city_id: { api.city_id} " )
40+
41+ # 4. Проверка наличия товара по магазинам
42+ balance = (await api.Catalog.Product.balance(product_id = first_product_id)).json()
43+ print (f " Проверено магазинов: { len (balance)} " )
44+
45+ # 5. Подробное инфо о товаре
46+ info = (await api.Catalog.Product.info(url = first_product_url)).json()
47+ print (f " Подробно о товаре: { list (info.keys())} " )
48+
49+ # 6. Загрузка изображения
50+ image_url = products[0 ][" images" ][0 ][" src" ]
51+ image_stream = await api.General.download_image(image_url)
52+ with Image.open(image_stream) as img:
53+ print (f " Image format: { img.format} , size: { img.size} " )
54+
55+
56+ if __name__ == " __main__" :
57+ asyncio.run(main())
4658
4759 .. code-block :: console
4860
0 commit comments