-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
31 lines (25 loc) · 1.35 KB
/
main.py
File metadata and controls
31 lines (25 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from perekrestok_api import PerekrestokAPI
from perekrestok_api import abstraction
import asyncio
async def main():
async with PerekrestokAPI() as Api:
geopos_handler = await Api.Geolocation.current()
geopos = geopos_handler.json()
print(f'Текущий город сессии {geopos["content"]["city"]["name"]} ({geopos["content"]["city"]["id"]})')
# Получаем список категорий
categories = await Api.Catalog.tree()
cat = categories.json()
print(f'Список категорий: {len(cat["content"]["items"])}')
# Выводим первую категорию
print(f'Категория: {cat["content"]["items"][0]["category"]["title"]} ({cat["content"]["items"][0]["category"]["id"]})')
# Получаем список товаров
filter = abstraction.CatalogFeedFilter()
filter.CATEGORY_ID = cat["content"]["items"][0]["category"]["id"]
filter.PROMO_LISTING = 27
products = await Api.Catalog.feed(filter=filter)
prod = products.json()
# Выводим первый товар
print(f'Первый товар: {prod["content"]["items"][0]["title"]} ({prod["content"]["items"][0]["id"]})')
# Запуск асинхронной функции main
if __name__ == "__main__":
asyncio.run(main())