Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

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.

Files for aio2ch, version 3.1.2
Filename, size File type Python version Upload date Hashes
Filename, size aio2ch-3.1.2-py3-none-any.whl (11.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aio2ch-3.1.2.tar.gz (10.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page