用于4chan api和其他imageboard的python包装器
py-chan-api的Python项目详细描述
py chan api
目标:
- unify:将其他图像板转换为json格式的4chan api
- wrapper:将json解析为编程语言特定的数据结构
- extra:下载json+media的能力
为什么?
我有很多线程存档在一个纯文本的链接列表中,用于教育目的。随着存档网站的出现,我意识到它不会一直在这里,我需要把它保存在本地。后来,它提醒我,不仅这些需要存档,而且在互联网上的其他一切,我的价值。
支持:
Feature | Source |
---|---|
✔️ Single thread | ^{ |
✔️ Thread index | ^{ |
✔️ Board list | ^{ |
✔️ Board catalog | ^{ |
✔️ Thread list | ^{ |
✔️ Archived threads | ^{ |
⚠️ HTTPS | On by default in ^{ |
⚠️ Rate limiting | ^{ |
⚠️ ^{ | ^{ |
⚠️ In-place thread updating | ^{ |
Extra Imageboards | Compatibility |
---|---|
✔️ FFuuka | ^{ |
❔ warosu | |
❔ yuki.la |
安装
pipinstallpy-chan-api# NOTE: Only Python 3.7+# Or with virtualenvpipinstallvirtualenv# Install virtualenv if you havent alreadyvirtualenvvenv# Create a virtualenvsourcevenv/bin/activate# Activate itpipinstall-rrequirements.txt# Install required modulespipinstallpy-chan-api# Install py-chan-api
使用量
importpychan# 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.thread=pychan.FourChan("thread.json")post=thread.posts[0]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")print(thread.posts[0].com)# Get the first post and its commentprint(post)# If you're unsure of what fields to call# just print the object itself to see a list of key/valuesprint(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/pairsjdb=thread.posts[0].json# Convert the Post object to a dictionaryfork,vinjdb.items():# Iterate through the key/value pairsprint(k,v)
转换
importpychanfuukaThread=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 jsonfthread=pychan.FourChan("out1.json")# We can also just use the outputed value from beforeprint(fthread1.posts[1])# Note: fthread1 is the same as fthread and fuukaThread
支持
欢迎拉取请求。 请随意ping shiimizu@thisMatrix服务器。