Deprecation Notice : Because tree holes frequently change APIs and recently introduced mandatory web UUID SMS verification, I no longer have the energy to maintain this project, so it will be abandoned. If you are interested in continuing to develop this project, you can continue to PR and contact me, or publish it to a new package name. Thanks again to everyone who has used and helped with development.
Important notice! ! : Because the original tree hole changed the authentication method and request address, the versions before v2.0.0 of this package are unavailable. Please update your project to v2.0.0 and above in time.
See below for the new version of tree hole authentication method
A simple Python interface to PKU Tree Hole
It is currently under continuous development and improvement, and we welcome the use and suggestions!
Published to Pypi source, you can install it directly using pip:
pip3 install TreeHoleYou have two ways to verify your identity:
You can pass in
uid(student number) andpassword(password) parameters when instantiatingTreeHoleClient, and log in with the IAAA account.
For how to obtain a tree hole token, please refer to @Guyutongxue's operating instructions (i.e. "Beida Tree hole JWT" in this instruction), you can also find it in the pku_token field in the browser's cookies.
from treehole import TreeHoleClient
# 使用 token 认证
client = TreeHoleClient ( token = < Your Token > )
# 使用 IAAA 账号认证
client = TreeHoleClient ( uid = < UID > , password = < Password > )
# 获取单个树洞
hole = client . get_hole ( < Hole ID > )
# 获取树洞评论
comments = client . get_comment ( < Hole ID > )
# 获取首页树洞列表
holes = client . get_holes ( < Page Num > )
# 获取关注树洞列表
holes = client . get_followed ( < Page Num > )
# 切换关注状态
success , status = client . post_toggle_followed ( < Hole ID > )
# 发布树洞
success = client . post_hole ( < Text > , < Image File > )
# 发布评论
success = client . post_comment ( < Hole ID > , < Text > , < Reply To > )
# 举报树洞 (!!!!!! 请勿轻易尝试)
success = client . post_report ( < Hole ID > , < Reason > )Please refer to non-asynchronous and asynchronous use cases
Clone this repository:
git clone [email protected]:TeddyHuang-00/pyTreeHole.gitIn editing mode:
pip3 install -e " .[test] "Welcome to issue and PR!