py-chan-api
Objective:
- Unification: Have one library to use for multiple imageboards. Convert them to 4chan compliant API specifications.
- Wrapper: Parse the JSON to programming-language-specific data structures (in this case, to Python).
API Documentation
4chan
FFuuka based Imageboards
| Feature | Source |
|---|---|
| ✔️ Single thread | a.4cdn.org/{board}/thread/{threadnumber}.json |
| ✔️ Thread index | a.4cdn.org/{board}/{pagenumber}.json (threads @ pg #) |
| ✔️ Board list | a.4cdn.org/boards.json |
| ✔️ Board catalog | a.4cdn.org/{board}/catalog.json |
| ✔️ Thread list | a.4cdn.org/{board}/threads.json |
| ✔️ Archived threads | a.4cdn.org/{board}/archive.json |
| 🚧 HTTPS | On by default in urllib3 |
| 🚧 Rate limiting | x requests allowed in n seconds |
🚧 If-Modified-Since |
req.headers['last-modified'] |
| 🚧 In-place thread updating | req.headers['last-modified']; difflib |
Extra Support
| Extra Imageboards | Compatibility |
|---|---|
| ✔️ FFuuka | Thread, Post |
| ❔ warosu | |
| ❔ yuki.la |
Installation
$ pip install py-chan-api # NOTE: Only Python 3.7+
# Or with virtualenv
$ pip install virtualenv # Install virtualenv if you haven't already
$ virtualenv venv # Create a virtualenv
$ source venv/bin/activate # Activate it
$ pip install py-chan-api # Install py-chan-api
Usage
import pychan
# pychan infers what type of object you're giving it. See the above table.
# Whether its a string pointing to a file/dict/dict in string format.
threadIndex = pychan.FourChan("thread_index.json")
board = pychan.FourChan("boards.json")
thread = pychan.FourChan("thread.json")
threadList = pychan.FourChan("thread_list.json")
archivedThread = pychan.FourChan("archived_threads.json")
post = thread.posts[0]
print(thread.posts[0].com) # Get the first post and its comment
print(post) # If you're unsure of what fields to call
# just print the object itself to see a list of key/values
# Or see the type of the unknown object
print(type(pychan.FourChan("unknown.json")))
print(thread.posts[0])
print(threadIndex.threads[0].posts[1])
print(board.trollflags.AC)
print(board.boards[0].title)
print(catalog.page[0].threads[0])
print(threadList.page[0].threads[0])
print(archivedThread[-1])
# To get individual key value/pairs
jdb = thread.posts[0].json # Convert the Post object to a dictionary
for k,v in jdb.items(): # Iterate through the key/value pairs
print(k, v)
Converting
import pychan
fuukaThread = pychan.Fuuka("desu_thread.json") # Specify the imageboard implementation
# Parallelism (multiprocessing) is turned on automatically if you supply more
# than one key/value pairs in a dictionary.
# You can override this behaviour by specifying the parallel field
# By using a dictionary, you can also output it to a file.
fthread1 = pychan.Fuuka({"desu_thread.json" : "out1.json"}, parallel = True)
# Which then you could read it as a normal 4chan json
fthread = pychan.FourChan("out1.json")
# We can also just use the outputed value from before
print(fthread1.posts[1]) # Note: fthread1 is the same as fthread and fuukaThread
Tests
Tests are done with pytest.
$ pip install -U pytest pytest-xdist
$ pytest tests.py -v
Support
Pull requests are welcome. Feel free to ping shiimizu @ this Matrix server.
⚠️ Archiving (polling)
- Archiving capabilities are beyond the scope of this project.
- Please see:
Metadata
Release files for py-chan-api 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py-chan-api-0.1.3.tar.gz | 7.5 kB | Without provenance | Details for py-chan-api-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_chan_api-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for py_chan_api-0.1.3-py3-none-any.whl |
Total release size: 16.0 kB
Release files / py-chan-api-0.1.3.tar.gz
| Download URL | py-chan-api-0.1.3.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4890aad0da59fda86f1ba7984e53d6fb19320c2de88d20884206327cdd95a76b
|
|
BLAKE2b-256 checksum How to use checksums |
6feef9025ce725df06fcce3daa0853b02c0f7661e94a8235e21b333830f33e22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3
|
Release files / py_chan_api-0.1.3-py3-none-any.whl
| Download URL | py_chan_api-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ca1ebf4d36c257fe85a96b128429a3ae2c11f14637f1e0cff5724770dc1d40b
|
|
BLAKE2b-256 checksum How to use checksums |
56441772e1863d48df843e5032ce3bc4d282179ac203dd9087f6d029bb25a54f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3
|
Security for py-chan-api 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.