Skip to main content

Fully asynchronous read-only API wrapper for 2ch.hk (dvach)

Project description

Logo

License Changelog Downloads PyPi Python

Fully asynchronous read-only API wrapper for 2ch.hk (dvach, Двач)

Requirements

Install with pip

$ pip3 install aio2ch

Build from source

$ git clone https://github.com/wkpn/aio2ch
$ cd ./aio2ch
$ python3 setup.py install

Usage

Simple usage (in this case client.close() must be called when client is no longer needed)

>>> from aio2ch import Api
>>> client = Api()
>>> ...
>>> await client.close()

Or you can use it as a context manager

>>> async with Api() as client:
...     boards = await client.get_boards()

Get all boards

>>> boards = await client.get_boards()

>>> boards
(<Board name='Фагготрия', id='fag'>, ... )

In addition we can get status for each method. This is useful for debug purposes or if retries are needed

>>> status, boards = await client.get_boards(return_status=True)

>>> status
200

>>> boards
(<Board name='Фагготрия', id='fag'>, ... )

Get all threads from a board

>>> threads = await client.get_board_threads(board="b")

>>> threads
(<Thread num='180981319'>, ... )

Get top threads from a board sorted by method (views, score or posts_count)

>>> top_threads = await client.get_top_board_threads(board="b", method="views", num=3)

>>> top_threads
(<Thread num='180894312'>, <Thread num='180946622'>, <Thread num='180963318'>)

Get all thread’s posts (thread is an instance of Thread)

>>> thread_posts = await client.get_thread_posts(thread=thread)

>>> thread_posts
(<Post num='180894312'>, ... )

Get all thread’s posts by url

>>> thread_posts = await client.get_thread_posts(thread="https://2ch.hk/test/res/30972.html")

>>> thread_posts
(<Post num='30972'>, ... )

Get all media in all thread’s posts (images, webm and so on)

>>> thread_media = await client.get_thread_media(thread=thread)

>>> thread_media
(<File name='15336559148500.jpg', path='/b/src/180979032/15336559148500.jpg', size='19'>, ... )

Get specific thread media

>>> images_and_videos = await client.get_thread_media(thread, media_type=(Image, Video))

>>> images_and_videos
(<Image name=...>, <Video name=...>, ...)

>>> just_images = await client.get_thread_media(thread, media_type=Image)

>>> just_images
(<Image name=...>, ...)

Download all thread media

>>> await client.download_thread_media(files=thread_media, save_to="./downloads")

Project details


Download files

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

Source Distribution

aio2ch-3.0.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

aio2ch-3.0.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file aio2ch-3.0.0.tar.gz.

File metadata

  • Download URL: aio2ch-3.0.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/46.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.7

File hashes

Hashes for aio2ch-3.0.0.tar.gz
Algorithm Hash digest
SHA256 5e72ab31b2ef7eaba28e255a7a4d11903ac712cb235dc06bd4627ccc72347294
MD5 52f6aaf8dfbe1048e8feb8dbda764396
BLAKE2b-256 bc8b685f5e7d88fa5123c13f16c73390b8dabc9af31e80c70b108aff4aa3d306

See more details on using hashes here.

File details

Details for the file aio2ch-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: aio2ch-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/46.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.7

File hashes

Hashes for aio2ch-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5615a66c2f192987fd868622aab777ab5764203158ef670fce27209fc9e46e5a
MD5 ec2c0c7dcb92f02661157a62204ec53b
BLAKE2b-256 5682393b8c6f5fa428aa830707e69a973ef1c4b53d593875e1d941e947b8009c

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