ustc-tools
中国科大校园工具的可复用业务库,要求 Python 3.11+,依赖独立的 ustc-sdk。
提供二课完整扫描、差异检测、搜索、筛选、报名与取消,以及学习空间预约预览、提交前复核和取消。
安装
uv add ustc-tools
uv add "ustc-tools[monitor]"
第二条包含可选的 APScheduler 3.x 定时监控模块。
扫描与查询
import asyncio
import os
from ustc_sdk import CASClient, YoungClient
from ustc_tools import ActivityService, SQLiteStore
async def main():
username = os.environ["USTC_USERNAME"]
async with CASClient(username, os.environ["USTC_PASSWORD"]) as cas:
async with YoungClient(cas) as young, SQLiteStore("state.sqlite3") as store:
service = ActivityService(young, store, user_id=username)
result = await service.scan()
print("baseline:", result.baseline)
print("changes:", len(result.changes))
print([activity.id for activity in await service.search("讲座")])
asyncio.run(main())
首次完整扫描建立基线。后续扫描返回结构化变化;读取失败时保留上一次完整快照。
ActivityPreferences 支持感兴趣/忽略标记、已报名过滤、固定忙时与周重复忙时。
select(predicate=...) 可接入调用方的异步内容或 AI 判断函数。
可报名筛选同时考虑报名时间与剩余名额。独立调用 filter_activities(..., now=...) 可传入带时区的时间;默认从输入的已报名活动推导冲突,enrolled=() 可显式忽略这些冲突。
深扫描保留报名状态,报名/取消返回的数据与保存到快照的状态一致。
ustc_tools.spaces.SpaceService 提供空间预约预览、成员和时段校验、提交前重新读取占用及稳定标识取消。
ustc_tools.monitor.Monitor 由调用方显式启动和停止,通过异步回调返回扫描结果。
预约成员默认按完整学号或姓名查询,纯数字学号也会查询;内部账号编号须明确写成 acc:<编号>。
预览保存原请求的独立副本,summary() 可用于确认提示。输入时段严格采用 HH:MM,更改预览时段后须重新预览。
监控的 stop() 可重复或并发调用;通知回调仍应由外部任务停止。
SQLite 存储位置和用户标识由应用提供。MemoryStore 用于临时脚本,ActivityStore 可替换为应用自己的存储。
两个内置存储均提供 last_scan(user_id),读取的快照、偏好和扫描结果不会与内部状态共享可变对象。
公开模型使用 Pydantic;MCP、网页和机器人适配由外部应用实现。
来源与许可
GPL-3.0-only。二课工作流参考 NextArc, 空间工作流参考 xtcli。 包附带 LICENSE、LICENSE-MIT 和 NOTICE;SDK 单独采用 MIT 许可。
Metadata
Release files for ustc-tools 0.3.0
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 |
|---|---|---|---|---|
| ustc_tools-0.3.0.tar.gz | 31.7 kB | Without provenance | Details for ustc_tools-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ustc_tools-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for ustc_tools-0.3.0-py3-none-any.whl |
Total release size: 64.4 kB
Release files / ustc_tools-0.3.0.tar.gz
| Download URL | ustc_tools-0.3.0.tar.gz |
|---|---|
| Size | 31.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85965234a792aa2bf2240cc1508c93cb79b5bc4720b7debce24bf73c6b9dd180
|
|
BLAKE2b-256 checksum How to use checksums |
733146e14a5c73341cbfa1ed158ec726c23b9c0043e4c1cff592b304e2291101
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / ustc_tools-0.3.0-py3-none-any.whl
| Download URL | ustc_tools-0.3.0-py3-none-any.whl |
|---|---|
| Size | 32.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91b2ea681dce552b2cde634e76e612d93d3a08851c996b88fd289a42018eb167
|
|
BLAKE2b-256 checksum How to use checksums |
85cdfbf384752e9fff5650b94d15f360ed487aa82efff11fdfd2921d0838f624
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for ustc-tools 0.3.0
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.