Skip to main content

AnoBBS Client

AnoBBS(A岛所用匿名版架构)API 的 Python 封装库。

GitHub license PyPI pyversions PyPI version shields.io GitHub issues

功能随个人需要增加。

注意⚠️:由于本库出发点的项目没有多线程需求,所以本库当前只以单线程使用为目的设计。虽然每个请求都奢侈地专门创建了一个新的 Session,但共用的 CookieJar 并非线程安全。

实现功能

  • 查看
    • 版块
    • 页面
    • 版块列表/版规介绍/…
    • 遍历
      • 反向遍历串页面
      • 遍历版块页面
  • 发布
    • 串
    • 回应
  • 添加订阅/删除订阅
  • 装载饼干
  • …

术语

  • 「卡页」「卡99」
    • 访问串的100页之后的页面,响应的会是100页的内容。

示例

毕竟只是自用,感觉也不会有其他人感兴趣,就不在这方面多费时间了。

下面都是些最基础的例子,剩下的就让源代码自己去解释吧 (ゝ∀・)

创建客户端

client = anobbsclient.Client(
    # 客户端的 User-Agent
    user_agent='…',
    # 目标服务器的主机名,如 'adnmb3.com'
    host='…',
    # 客户端的 appid,可为 `None`
    appid='…',
    # 与单次请求相关的一些选项,发送请求时可以选择覆盖这些选项
    default_request_options={
        # 在浏览器中以名为 userhash 的 cookie 的形式呈现,登录的凭证。
        # 领饼干领的就是这个。
        # 在需要提供此值(如访问超过100页的页面)而此值空缺时
        # 会直接抛异常
        'user_cookie': '…',
        # 要怎么处理登录:
        # 'enforce':            无论如何都会在请求中包含 user_cookie。
        #                       无论操作是否需要登录,都要提供 user_cookie
        # 'when_has_cookie':    只要提供了 user_cookie,就会在请求中包含它
        # 'when_required':      当需要进行需要登录的操作时,
        #                       才会在请求中包含 user_cookie
        # 'always_no':          无论如何都不在请求中包含 user_cookie。
        #                       遇到需要登录的操作会直接抛异常
        'login_policy': 'when_required',
    },
)

获取串内容

luwei_thread = client.get_thread_page(49607, page=1)

print(luwei_thread.content) #=> '这是芦苇'

获取版块内容

g_board = client.get_board_page(4, page=1)

print(g_board[0].user_id) #=> 'ATM'

发布回应

try:
    client.reply_thread(
        "正文内容", to_thread_id=999999999999,
        title="标题(可选)", name="名称(可选)",
        email="邮箱(可选)",
    )
except anobbsclient.ReplyException as e:
    # 服务器不接受所发回应
    print(e.raw_error, e.raw_detail)
    raise e

反向遍历串页面

Q:为何这么做?A:防止遍历途中有串被抽导致遗漏。

例子略,只是表示有这个功能 (ゝ∀・)

Release files for anobbs-client 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anobbs-client 0.0.4
File Size Uploaded
anobbs-client-0.0.4.tar.gz 16.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for anobbs-client 0.0.4
File Interpreter ABI Platform
anobbs_client-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 40.9 kB

Release files / anobbs-client-0.0.4.tar.gz

Download URL anobbs-client-0.0.4.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d05512797502752539a179ba30c92d8c83d2942e3b55a2efc9ef3e5daf8dbf11
BLAKE2b-256 checksum
How to use checksums
e8a8e69f26dabd06a9e2cfb3a0ff8799661f0d399c4e6eefc85d72907a713ca2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

Release files / anobbs_client-0.0.4-py3-none-any.whl

Download URL anobbs_client-0.0.4-py3-none-any.whl
Size 24.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f3b2e811e30427856fcc449a1cf02252142001c3a6176720decd7d0e3e62e86
BLAKE2b-256 checksum
How to use checksums
ed04a0d0066651e8740b19739ab770dd37133c3c132a4d66305aa8662e370a3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page