Skip to main content

Асинхронный клиент для итд.com

Project description

aioitd

Асинхронный Python клиент для итд.com

Установка

pip install aioitd

Пример

from aioitd import AsyncITDClient
import asyncio

refresh_token = "ca1291a4a990b985a57b880ed3fb863eef80ac3990acc68e8f106a783e3af402"

async def main():
    async with AsyncITDClient(refresh_token) as client:
        user = await client.get_user("nowkie")
        print(
            f"id: {user.id}\n"
            f"username: {user.username}\n"
            f"follower_count: {user.followers_count}"
        )

asyncio.run(main())

Чтобы получить refresh_token:

  1. Войди в аккаунт на итд.com
  2. Откройть devtools
  3. Среди табов выбрать network (сеть)
  4. Перезагрузить страницу
  5. Найти запрос refresh
  6. В куки запроса скопировать refresh_token

Или:

  1. Войти в аккаунт на итд.com
  2. Откройть devtools
  3. Среди табов выбрать application (приложение)
  4. Выбрать куки и скопировать токен

AsyncITDClient

Автоматически вызывает refersh, по окончании срока жизни access токена.

async with AsyncITDClient(refresh_token) as client:

или

client = AsyncITDClient(refresh_token)
...
await client.close()

Создание поста

from aioitd import AsyncITDClient, File, Post
import asyncio
from uuid import UUID

refresh_token = "ВАШ ТОКЕН"

async def main():
    async with AsyncITDClient(refresh_token) as client:
        images_path = ["sun.png", "снег.gif", "python.jpg"]
        files_ids: list[UUID] = []
        for path in images_path:
            with open(path, 'rb') as f:
                file: File = await client.upload_file(f)
                files_ids.append(file.id)
        post: Post = await client.create_post("ТЕКСТ ПОСТА", attachment_ids=files_ids)


asyncio.run(main())

Поменять баннер

async def main():
    async with AsyncITDClient(refresh_token) as client:
        with open(r"file.gif", 'rb') as file:
            image = await client.upload_file(file)
        await client.update_profile(username="aioitd", banner_id=image.id)

Error429 и RateLimitError

Error429 возникает из-за ограничения количества запросов на сервер. Чтобы обойти, нужно соблюдать интервал между запросами. Его можно указать в time_delta, и по умолчанию он равен 0.105 секунд.

async with AsyncITDClient(refresh_token, time_delta=1)

Чтобы отключить задержку между запросами:

async with AsyncITDClient(refresh_token, time_delta=None)

RateLimitError ограничение по количеству определённых действий для каждого аккаунта. retray_after — через сколько можно повторить запрос.

while True:
    try:
        await client.post("content")
    except RateLimitError as ex:
        await asyncio.sleep(ex.retry_after)

Уведомления по SSE

async def main():
    async with AsyncITDClient(refresh_token) as itd:
        async with itd.connect_sse() as events:
            async for event in events:
                print(event)

asyncio.run(main())

Автор в итд aioitd, тг @rationessEps

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aioitd-0.2.5-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file aioitd-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: aioitd-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for aioitd-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f418e5e0cc4fe1cdfff7394e2c4e620f5786a08e1b6595812bc7d8a183d061de
MD5 b5593ae1311d6bff18acb6a86c115ef9
BLAKE2b-256 a06f0e8d49e53f4c9173cae7c8d1e9119a82b40b803aa4439dd0dd0e86a772c8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page