Skip to content

Commit bcf89fc

Browse files
committed
Create example.py
1 parent 5e5e9c4 commit bcf89fc

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

example.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from chizhik_api import ChizhikAPI
2+
3+
async def main():
4+
# RUS: Использование проксирования опционально. Вы можете создать несколько агентов с разными прокси для ускорения парса.
5+
# ENG: Proxy usage is optional. You can create multiple agents with different proxies for faster parsing.
6+
async with ChizhikAPI(headless=False) as API:
7+
# RUS: Выводит активные предложения магазина
8+
# ENG: Outputs active offers of the store
9+
print(f"Active offers output: {(await API.Advertising.active_inout()).json()!s:.100s}...\n")
10+
11+
# RUS: Выводит список городов соответствующих поисковому запросу (только на русском языке)
12+
# ENG: Outputs a list of cities corresponding to the search query (only in Russian language)
13+
city_list = (await API.Geolocation.cities_list(search_name='ар', page=1)).json()
14+
print(f"Cities list output: {city_list!s:.100s}...\n")
15+
# Счет страниц с единицы / index starts from 1
16+
17+
# RUS: Выводит список всех категорий на сайте
18+
# ENG: Outputs a list of all categories on the site
19+
catalog = (await API.Catalog.tree()).json()
20+
print(f"Categories list output: {catalog!s:.100s}...\n")
21+
22+
# RUS: Выводит список всех товаров выбранной категории (ограничение 100 элементов, если превышает - запрашивайте через дополнительные страницы)
23+
# ENG: Outputs a list of all items in the selected category (limiting to 100 elements, if exceeds - request through additional pages)
24+
items = (await API.Catalog.products_list(category_id=catalog[0]['id'], page=1)).json()
25+
print(f"Items list output: {items!s:.100s}...\n")
26+
# Счет страниц с единицы / index starts from 1
27+
28+
# RUS: Сохраняем изображение с сервера (в принципе, сервер отдал бы их и без обертки моего объекта, но лучше максимально претворяться обычным пользователем)
29+
# 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)
30+
image = await API.General.download_image(items['items'][0]['images'][0]['image'])
31+
with open(image.name, 'wb') as f:
32+
f.write(image.read())
33+
34+
import asyncio
35+
asyncio.run(main())

0 commit comments

Comments
 (0)