Name | TreeHole JSON |
Version |
2.0.0
JSON |
| download |
home_page | |
Summary | A Python interface to PKU Hole! |
upload_time | 2023-01-11 18:41:22 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.6 |
license | |
keywords |
pku
hole
treehole
aiohttp
requests
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
**重要通知!!**:由于原树洞更改了鉴权方式和请求地址,导致本包 v2.0.0 之前的版本均不可用,请及时将您的项目更新至 v2.0.0 及以上版本。
新版本树洞认证方法见[下文](#身份验证)
---
# TreeHole
> A simple Python interface to PKU Tree Hole
[![GitHub - License](https://img.shields.io/github/license/TeddyHuang-00/pyTreeHole?color=f1f2f6&logo=github&style=for-the-badge)](https://github.com/TeddyHuang-00/pyTreeHole/blob/main/LICENSE.txt)
[![Git - Last Doc Commit](https://img.shields.io/github/last-commit/TeddyHuang-00/pyTreeHole/gh-pages?color=a4b0be&logo=readthedocs&style=for-the-badge&label=documentation)](https://teddyhuang-00.github.io/pyTreeHole)
[![PyPI - Version](https://img.shields.io/pypi/v/treehole?color=2980b9&label=version&logo=python&style=for-the-badge)](https://pypi.org/project/treehole/)
[![PyPI - Downloads per month](https://img.shields.io/pypi/dm/TreeHole?color=01579b&label=downloads&logo=pypi&style=for-the-badge)](https://pypistats.org/packages/treehole)
![Pytest - Result](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FTeddyHuang-00%2FpyTreeHole%2Fmain%2Ftests%2Ftest_result.json&color=0097e0&logo=pytest&style=for-the-badge)
[![Git - Last Commit](https://img.shields.io/github/last-commit/TeddyHuang-00/pyTreeHole?color=c0392b&logo=git&style=for-the-badge)](https://github.com/TeddyHuang-00/pyTreeHole)
目前正在持续开发完善中,欢迎使用和提出建议!
## 亮点
- 简单易用
- 文档齐全
- token 登陆
- Python 3.6+
- 支持异步请求
- 自动处理图像 url
- 所有树洞数据模型均已封装为数据类
- 涵盖(几乎?)所有暴露给用户的业务逻辑
## 安装
已发布至 Pypi 源,可直接使用 pip 安装:
```bash
pip3 install TreeHole
```
## 使用
### 身份验证
您有两种方式来验证身份:
1. 使用用户名和密码登陆(不推荐)
> 可以在实例化 `TreeHoleClient` 时传入 `uid`(学号)和 `password`(密码)参数即可,使用 IAAA 账号登陆
2. 使用 token 登陆(推荐,相对安全)
> 树洞 token 的获取方式请参考 @Guyutongxue 的[操作说明](https://github.com/Guyutongxue/pkuhelper-web-score/blob/master/docs/treehole-jwt.md)(即此说明中的“北大树洞 JWT”),您也可以在浏览器的 cookies 中的 pku_token 字段处找到它。
### 代码示例
```python
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>)
```
用例请参考 [非异步](./tests/sample.py) 和 [异步](./tests/sample_async.py)
## 开发
克隆此仓库:
```bash
git clone git@github.com:TeddyHuang-00/pyTreeHole.git
```
编辑模式下:
```bash
pip3 install -e ".[test]"
```
欢迎提 issues 与 PR!
## Roadmap
- [x] 支持新版树洞
- [x] 支持 IAAA 账号登陆
- [x] 树洞数据模型
- [x] 客户端封装
- [x] 获取单个树洞
- [x] 获取首页树洞
- [x] 获取关注树洞
- [x] 获取树洞回复
- [x] 关注/取关树洞
- [x] 回复树洞
- [x] 发布树洞
- [x] 举报树洞
- [x] 支持异步处理
- [x] 支持自定义加载长度
- [ ] 更多功能待补充 ...
Raw data
{
"_id": null,
"home_page": "",
"name": "TreeHole",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "pku,hole,treehole,aiohttp,requests",
"author": "",
"author_email": "TeddyHuang-00 <huang_nan_2019@pku.edu.cn>",
"download_url": "https://files.pythonhosted.org/packages/2c/da/9759777e3c8229788dab3e7331b762423899df720d3afc1d3f3c7c5ae56b/TreeHole-2.0.0.tar.gz",
"platform": null,
"description": "**\u91cd\u8981\u901a\u77e5\uff01\uff01**\uff1a\u7531\u4e8e\u539f\u6811\u6d1e\u66f4\u6539\u4e86\u9274\u6743\u65b9\u5f0f\u548c\u8bf7\u6c42\u5730\u5740\uff0c\u5bfc\u81f4\u672c\u5305 v2.0.0 \u4e4b\u524d\u7684\u7248\u672c\u5747\u4e0d\u53ef\u7528\uff0c\u8bf7\u53ca\u65f6\u5c06\u60a8\u7684\u9879\u76ee\u66f4\u65b0\u81f3 v2.0.0 \u53ca\u4ee5\u4e0a\u7248\u672c\u3002\n\n\u65b0\u7248\u672c\u6811\u6d1e\u8ba4\u8bc1\u65b9\u6cd5\u89c1[\u4e0b\u6587](#\u8eab\u4efd\u9a8c\u8bc1)\n\n---\n\n# TreeHole\n\n> A simple Python interface to PKU Tree Hole\n\n[![GitHub - License](https://img.shields.io/github/license/TeddyHuang-00/pyTreeHole?color=f1f2f6&logo=github&style=for-the-badge)](https://github.com/TeddyHuang-00/pyTreeHole/blob/main/LICENSE.txt)\n[![Git - Last Doc Commit](https://img.shields.io/github/last-commit/TeddyHuang-00/pyTreeHole/gh-pages?color=a4b0be&logo=readthedocs&style=for-the-badge&label=documentation)](https://teddyhuang-00.github.io/pyTreeHole)\n\n[![PyPI - Version](https://img.shields.io/pypi/v/treehole?color=2980b9&label=version&logo=python&style=for-the-badge)](https://pypi.org/project/treehole/)\n[![PyPI - Downloads per month](https://img.shields.io/pypi/dm/TreeHole?color=01579b&label=downloads&logo=pypi&style=for-the-badge)](https://pypistats.org/packages/treehole)\n\n![Pytest - Result](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FTeddyHuang-00%2FpyTreeHole%2Fmain%2Ftests%2Ftest_result.json&color=0097e0&logo=pytest&style=for-the-badge)\n[![Git - Last Commit](https://img.shields.io/github/last-commit/TeddyHuang-00/pyTreeHole?color=c0392b&logo=git&style=for-the-badge)](https://github.com/TeddyHuang-00/pyTreeHole)\n\n\u76ee\u524d\u6b63\u5728\u6301\u7eed\u5f00\u53d1\u5b8c\u5584\u4e2d\uff0c\u6b22\u8fce\u4f7f\u7528\u548c\u63d0\u51fa\u5efa\u8bae\uff01\n\n## \u4eae\u70b9\n\n- \u7b80\u5355\u6613\u7528\n- \u6587\u6863\u9f50\u5168\n- token \u767b\u9646\n- Python 3.6+\n- \u652f\u6301\u5f02\u6b65\u8bf7\u6c42\n- \u81ea\u52a8\u5904\u7406\u56fe\u50cf url\n- \u6240\u6709\u6811\u6d1e\u6570\u636e\u6a21\u578b\u5747\u5df2\u5c01\u88c5\u4e3a\u6570\u636e\u7c7b\n- \u6db5\u76d6(\u51e0\u4e4e\uff1f)\u6240\u6709\u66b4\u9732\u7ed9\u7528\u6237\u7684\u4e1a\u52a1\u903b\u8f91\n\n## \u5b89\u88c5\n\n\u5df2\u53d1\u5e03\u81f3 Pypi \u6e90\uff0c\u53ef\u76f4\u63a5\u4f7f\u7528 pip \u5b89\u88c5\uff1a\n\n```bash\npip3 install TreeHole\n```\n\n## \u4f7f\u7528\n\n### \u8eab\u4efd\u9a8c\u8bc1\n\n\u60a8\u6709\u4e24\u79cd\u65b9\u5f0f\u6765\u9a8c\u8bc1\u8eab\u4efd\uff1a\n\n1. \u4f7f\u7528\u7528\u6237\u540d\u548c\u5bc6\u7801\u767b\u9646\uff08\u4e0d\u63a8\u8350\uff09\n > \u53ef\u4ee5\u5728\u5b9e\u4f8b\u5316 `TreeHoleClient` \u65f6\u4f20\u5165 `uid`\uff08\u5b66\u53f7\uff09\u548c `password`\uff08\u5bc6\u7801\uff09\u53c2\u6570\u5373\u53ef\uff0c\u4f7f\u7528 IAAA \u8d26\u53f7\u767b\u9646\n2. \u4f7f\u7528 token \u767b\u9646\uff08\u63a8\u8350\uff0c\u76f8\u5bf9\u5b89\u5168\uff09\n > \u6811\u6d1e token \u7684\u83b7\u53d6\u65b9\u5f0f\u8bf7\u53c2\u8003 @Guyutongxue \u7684[\u64cd\u4f5c\u8bf4\u660e](https://github.com/Guyutongxue/pkuhelper-web-score/blob/master/docs/treehole-jwt.md)\uff08\u5373\u6b64\u8bf4\u660e\u4e2d\u7684\u201c\u5317\u5927\u6811\u6d1e JWT\u201d\uff09\uff0c\u60a8\u4e5f\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u7684 cookies \u4e2d\u7684 pku_token \u5b57\u6bb5\u5904\u627e\u5230\u5b83\u3002\n\n### \u4ee3\u7801\u793a\u4f8b\n\n```python\nfrom treehole import TreeHoleClient\n\n# \u4f7f\u7528 token \u8ba4\u8bc1\nclient = TreeHoleClient(token=<Your Token>)\n# \u4f7f\u7528 IAAA \u8d26\u53f7\u8ba4\u8bc1\nclient = TreeHoleClient(uid=<UID>, password=<Password>)\n# \u83b7\u53d6\u5355\u4e2a\u6811\u6d1e\nhole = client.get_hole(<Hole ID>)\n# \u83b7\u53d6\u6811\u6d1e\u8bc4\u8bba\ncomments = client.get_comment(<Hole ID>)\n# \u83b7\u53d6\u9996\u9875\u6811\u6d1e\u5217\u8868\nholes = client.get_holes(<Page Num>)\n# \u83b7\u53d6\u5173\u6ce8\u6811\u6d1e\u5217\u8868\nholes = client.get_followed(<Page Num>)\n# \u5207\u6362\u5173\u6ce8\u72b6\u6001\nsuccess, status = client.post_toggle_followed(<Hole ID>)\n# \u53d1\u5e03\u6811\u6d1e\nsuccess = client.post_hole(<Text>, <Image File>)\n# \u53d1\u5e03\u8bc4\u8bba\nsuccess = client.post_comment(<Hole ID>, <Text>, <Reply To>)\n# \u4e3e\u62a5\u6811\u6d1e (!!!!!! \u8bf7\u52ff\u8f7b\u6613\u5c1d\u8bd5)\nsuccess = client.post_report(<Hole ID>, <Reason>)\n```\n\n\u7528\u4f8b\u8bf7\u53c2\u8003 [\u975e\u5f02\u6b65](./tests/sample.py) \u548c [\u5f02\u6b65](./tests/sample_async.py)\n\n## \u5f00\u53d1\n\n\u514b\u9686\u6b64\u4ed3\u5e93\uff1a\n\n```bash\ngit clone git@github.com:TeddyHuang-00/pyTreeHole.git\n```\n\n\u7f16\u8f91\u6a21\u5f0f\u4e0b\uff1a\n\n```bash\npip3 install -e \".[test]\"\n```\n\n\u6b22\u8fce\u63d0 issues \u4e0e PR\uff01\n\n## Roadmap\n\n- [x] \u652f\u6301\u65b0\u7248\u6811\u6d1e\n- [x] \u652f\u6301 IAAA \u8d26\u53f7\u767b\u9646\n- [x] \u6811\u6d1e\u6570\u636e\u6a21\u578b\n- [x] \u5ba2\u6237\u7aef\u5c01\u88c5\n- [x] \u83b7\u53d6\u5355\u4e2a\u6811\u6d1e\n- [x] \u83b7\u53d6\u9996\u9875\u6811\u6d1e\n- [x] \u83b7\u53d6\u5173\u6ce8\u6811\u6d1e\n- [x] \u83b7\u53d6\u6811\u6d1e\u56de\u590d\n- [x] \u5173\u6ce8/\u53d6\u5173\u6811\u6d1e\n- [x] \u56de\u590d\u6811\u6d1e\n- [x] \u53d1\u5e03\u6811\u6d1e\n- [x] \u4e3e\u62a5\u6811\u6d1e\n- [x] \u652f\u6301\u5f02\u6b65\u5904\u7406\n- [x] \u652f\u6301\u81ea\u5b9a\u4e49\u52a0\u8f7d\u957f\u5ea6\n- [ ] \u66f4\u591a\u529f\u80fd\u5f85\u8865\u5145 ...\n",
"bugtrack_url": null,
"license": "",
"summary": "A Python interface to PKU Hole!",
"version": "2.0.0",
"split_keywords": [
"pku",
"hole",
"treehole",
"aiohttp",
"requests"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1c7c168710fb2c12d52b285d7b35823beccecdf696ebd09dae351000c55d723d",
"md5": "33674dccfa2cb7c65814feb0aa48813f",
"sha256": "9bd881e6f3f09a06767b11a87740eed386c63a5ebb96826764bed559d7928b51"
},
"downloads": -1,
"filename": "TreeHole-2.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "33674dccfa2cb7c65814feb0aa48813f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 12178,
"upload_time": "2023-01-11T18:41:20",
"upload_time_iso_8601": "2023-01-11T18:41:20.977930Z",
"url": "https://files.pythonhosted.org/packages/1c/7c/168710fb2c12d52b285d7b35823beccecdf696ebd09dae351000c55d723d/TreeHole-2.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2cda9759777e3c8229788dab3e7331b762423899df720d3afc1d3f3c7c5ae56b",
"md5": "eeb1203f1abba036dbd7361b3d386740",
"sha256": "ee50931adf2d31ac576269234361b6e5a1526a7937e91ad42ca18cf0eccb632f"
},
"downloads": -1,
"filename": "TreeHole-2.0.0.tar.gz",
"has_sig": false,
"md5_digest": "eeb1203f1abba036dbd7361b3d386740",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 11917,
"upload_time": "2023-01-11T18:41:22",
"upload_time_iso_8601": "2023-01-11T18:41:22.710804Z",
"url": "https://files.pythonhosted.org/packages/2c/da/9759777e3c8229788dab3e7331b762423899df720d3afc1d3f3c7c5ae56b/TreeHole-2.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-11 18:41:22",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "treehole"
}