Metadata-Version: 2.4
Name: ustc-tools
Version: 0.1.0
Summary: Composable USTC activity and learning-space workflows
License-Expression: GPL-3.0-only
License-File: LICENSE
License-File: LICENSE-MIT
License-File: NOTICE
Requires-Dist: ustc-sdk>=0.1.0,<0.2
Requires-Dist: aiosqlite>=0.21,<1
Requires-Dist: pydantic>=2.11,<3
Requires-Dist: apscheduler>=3.11,<4 ; extra == 'monitor'
Requires-Python: >=3.11
Project-URL: Repository, https://github.com/RaymondzyLei/tools-at-USTC
Project-URL: Issues, https://github.com/RaymondzyLei/tools-at-USTC/issues
Provides-Extra: monitor
Description-Content-Type: text/markdown

# ustc-tools

中国科大校园工具的可复用业务库，要求 Python 3.11+，依赖独立的 `ustc-sdk`。
提供二课完整扫描、差异检测、搜索、筛选、报名与取消，以及学习空间预约预览、提交前复核和取消。

## 安装（发布后）

```text
uv add ustc-tools
uv add "ustc-tools[monitor]"
```

第二条包含可选的 APScheduler 3.x 定时监控模块。

## 扫描与查询

```python
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 判断函数。

`ustc_tools.spaces.SpaceService` 提供空间预约预览、成员和时段校验、提交前重新读取占用及稳定标识取消。
`ustc_tools.monitor.Monitor` 由调用方显式启动和停止，通过异步回调返回扫描结果。

SQLite 存储位置和用户标识由应用提供。`MemoryStore` 用于临时脚本，`ActivityStore` 可替换为应用自己的存储。
公开模型使用 Pydantic；MCP、网页和机器人适配由外部应用实现。

## 来源与许可

GPL-3.0-only。二课工作流参考 [NextArc](https://github.com/RaymondzyLei/NextArc/tree/49c858b8e0ff7e11020fdc4cd8e1e520ca126935)，
空间工作流参考 [xtcli](https://git.ustc.edu.cn/yu-z.h/xtcli/-/tree/e8c0116f7b95970300e6db1af5b03547166184d5)。
包附带 LICENSE、LICENSE-MIT 和 NOTICE；SDK 单独采用 MIT 许可。

[源码与完整文档](https://github.com/RaymondzyLei/tools-at-USTC)
