Skip to main content

API wrapper for 4chan.

Project description

Contents

  • 4chan API reader.

Installing

python3 -m pip install aio4chan

Usage

import asyncio
import aiohttp
import aio4chan

loop = asyncio.get_event_loop()

session = aiohttp.ClientSession(loop = loop)

client = aio4chan.Client(session = session, loop = loop)

async def execute():

    """
    Traverse 4chan.
    """

    boards = await client.get_boards()

    # short names
    board_ids = (board.board for board in boards)

    for board_id in board_ids:

        pages = await client.get_threads(board_id)

        # list of pages, each containing threads
        thread_ids = (thread.no for page in pages for thread in page.threads)

        for thread_id in thread_ids:

            # need both board_id and thread_id
            thread = await client.get_thread(board_id, thread_id)

            for post in thread:

                try:

                    # might not exist
                    comment = post.com

                except AttributeError:

                    continue

                # print where we got it, and the comment
                print(board_id, '>', thread_id, '>', post.no, '\n', post.com)

try:

    loop.run_until_complete(execute())

except KeyboardInterrupt:

    pass

finally:

    loop.run_until_complete(session.close())

    loop.close()

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

aio4chan-0.0.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

aio4chan-0.0.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file aio4chan-0.0.0.tar.gz.

File metadata

  • Download URL: aio4chan-0.0.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for aio4chan-0.0.0.tar.gz
Algorithm Hash digest
SHA256 cec2f933a27753b0f06e77fe2a12df337bfc61e75c4380ac13ecb5ac3f2e5697
MD5 5a9c7ec75c092a989a16437767359b66
BLAKE2b-256 e0b1f71e42148d495fc114ac82afcd1e7b55dc0c5a844a176100e704e2e2c632

See more details on using hashes here.

File details

Details for the file aio4chan-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: aio4chan-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for aio4chan-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a9c6c01c41537782db44d0abf8ead9fc423207f6364712365b48ed56b320866
MD5 3b7bd67017f2a26727373df410aa9455
BLAKE2b-256 f3c5bd14b7ad300dc0da6bf75f24b97ea589496d3adde786b85c47e57226eff5

See more details on using hashes here.

Supported by

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