Skip to main content

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.2.1

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

Source distribution (sdist)

Source distribution for ustc-tools 0.2.1
File Size Uploaded Provenance Actions
ustc_tools-0.2.1.tar.gz 31.4 kB Without provenance Details for ustc_tools-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ustc-tools 0.2.1
File Interpreter ABI Platform Actions
ustc_tools-0.2.1-py3-none-any.whl Python 3 none any Details for ustc_tools-0.2.1-py3-none-any.whl

Total release size: 63.9 kB

Release files / ustc_tools-0.2.1.tar.gz

Download URL ustc_tools-0.2.1.tar.gz
Size 31.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7811c874818e37ca8d30fecc10fa40d48f627ea5f9207590f38dd5b3a81a069c
BLAKE2b-256 checksum
How to use checksums
d0d2135a9afdce4eb02393ee724268bde3096e785e68825d13ddadc8fe6abfa0
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.2.1-py3-none-any.whl

Download URL ustc_tools-0.2.1-py3-none-any.whl
Size 32.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
386225b7c0bb9ebfe976ebac84e3bb677bd8f2cdd1e225838ca596e62697b0e6
BLAKE2b-256 checksum
How to use checksums
7ad1fb98bd200439659debe226babb005be5321dc161d7ebe571922d33f4c702
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.2.1

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.

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