Metadata-Version: 2.4
Name: autotd-buaa
Version: 0.1.1
Summary: BUAA TD automation command line utility
Author: autoTD maintainers
Keywords: buaa,td,cli
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# AutoTD

`autoTD` 是一个可安装的命令行工具包。安装后提供 `autotd` 命令，用于初始化本地配置目录、管理用户和图片、运行 TD 打卡流程、查询服务器返回的本学期锻炼次数，以及以前台进程方式进行定时轮询。

> `autotd user count` 会发送真实 `checkdata` 请求来解析服务器消息中的次数，可能产生服务器侧刷卡/打卡记录。

## 安装与打包

本项目采用标准 `pyproject.toml` 包结构：

```bash
python3 -m pip install -e .
autotd --help
```

构建本地 wheel/sdist：

```bash
python3 -m build
```

内部测试发布可使用 TestPyPI：

```bash
python3 -m twine upload --repository testpypi dist/*
```

## 初始化

所有运行数据存储在 `~/.autoTD` 下。测试或临时运行时可用 `AUTOTD_HOME` 覆盖：

```bash
autotd init
autotd init --from ./autoTD
```

目录结构：

```text
~/.autoTD/
├── config.json
├── users.json
├── settings.json
├── state.json
├── images/
└── logs/
    └── YYYY-MM-DD-daytime-log.txt
```

## 用户管理

```bash
autotd user add 22375080 --entrance 2 --exit 6 --entrance-image image3.jpg --exit-image image2.jpg
autotd user add 22375080 --quick 沙河
autotd user add 22375080 --quick 学院路
autotd user list
autotd user show 22375080
autotd user update 22375080 --card-id CARDID --entrance 3 --exit 7 --entrance-image image1.jpg --exit-image image2.jpg
autotd user delete 22375080
autotd user count 22375080
```

`card_id` 为空时会自动使用学号的 16 进制大写形式。

使用 `--quick` 时，只需要指定校区：

- `--quick 沙河`: 随机选择沙河入口机 `8/9/10`、沙河出口机 `11/12/13`，并从 `~/.autoTD/images/` 随机选择入口/出口图片。
- `--quick 学院路`: 随机选择学院路/本部入口机 `2/3/4`、学院路/本部出口机 `5/6/7`，并从 `~/.autoTD/images/` 随机选择入口/出口图片。
- 其他字段使用默认值：`rounds=3`、`wait_time_min=180`、`wait_time_max=240`、`card_id` 自动生成。

## 图片管理

```bash
autotd image add ./image3.jpg
autotd image add ./photo.jpg --name entrance.jpg
autotd image add ./photo.jpg --name entrance.jpg --overwrite
autotd image list
```

图片会复制到 `~/.autoTD/images/`。用户配置中引用的是图片文件名。

## 运行

立即执行一次所有用户：

```bash
autotd run --once
```

如果定时开关关闭，`autotd run` 也会立即执行一次。执行时某个用户失败会记录日志并继续后续用户。

## 定时运行

定时运行是前台常驻进程，不创建系统服务。

```bash
autotd schedule show
autotd schedule enable
autotd schedule disable
autotd schedule set --poll-seconds 60 --windows "07:30-10:00,11:30-14:00,15:30-20:00"
autotd run
```

默认时间段为：

- 07:30 - 10:00
- 11:30 - 14:00
- 15:30 - 20:00

定时模式按北京时间判断日期。一天只会做一次定时批量尝试；无论成功或失败，当天都不会自动重试。

## 测试

```bash
python3 -m unittest discover -s tests -v
```
