Files
GPA_Monitoring/readme.md
ChuXun 609b2334e8 1
2026-01-18 18:48:20 +08:00

157 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 成绩监控系统
自动监控东北大学成绩系统,当有新课程成绩发布时自动发送邮件通知。
## 快速开始
### 1. 安装依赖WSL环境
```bash
cd /mnt/e/50425/Documents/Github/GPA_Monitoring
chmod +x setup_python.sh
./setup_python.sh
```
### 2. 配置
编辑 `config.ini` 文件,填入你的信息:
```ini
[login]
USERNAME = 你的学号
PASSWORD = 你的密码
[email]
SENDER_EMAIL = your_email@163.com
SENDER_PASSWORD = SMTP授权码不是邮箱密码
RECEIVER_EMAIL = 接收通知的邮箱
```
**获取163邮箱SMTP授权码**
1. 登录163邮箱网页版
2. 设置 → POP3/SMTP/IMAP
3. 开启"IMAP/SMTP服务"
4. 发送短信获取授权码
### 3. 测试运行
```bash
source venv/bin/activate
python3 monitor.py --test
```
检查生成的文件确认内容正确:
- `.last_grade_content.txt` - 提取的成绩内容(整齐格式)
- `.last_grade_page.html` - 原始HTML页面
### 4. 正式运行
```bash
# 使用tmux后台运行推荐
tmux new -s grade_monitor
source venv/bin/activate
python3 monitor.py
# 按 Ctrl+B 然后按 D 离开会话
```
## 功能特点
**智能检测** - 检测新增课程(而非简单的页面变化)
**详细通知** - 邮件包含新增课程名称
**格式化输出** - 成绩保存为整齐的文本格式,包含总绩点
**错误通知** - 连续失败5次自动发送错误通知邮件
**稳定可靠** - 自动重试、会话管理、异常处理
**防封禁** - 请求间隔控制,避免过快访问
## 文件说明
**主要文件:**
- `monitor.py` - 主程序
- `config.ini` - 配置文件
- `requirements.txt` - Python依赖
- `setup_python.sh` - 安装脚本
**自动生成的文件:**
- `.last_grade_content.txt` - 当前成绩内容(格式化)
- `.last_grade_page.html` - 原始HTML页面
- `.last_courses.txt` - 课程列表(用于检测新增)
- `.last_grade_hash.txt` - 内容哈希(用于检测变化)
- `monitor.log` - 运行日志
## 命令说明
```bash
# 查看帮助
python3 monitor.py --help
# 测试模式(获取一次成绩)
python3 monitor.py --test
# 正常监控模式
python3 monitor.py
# 查看日志
tail -f monitor.log
# 查看成绩
cat .last_grade_content.txt
```
## 监控原理
1. **定时访问** - 每60秒可配置访问一次成绩页面
2. **解析成绩** - 提取总绩点和每门课程信息
3. **智能对比** - 对比课程列表,检测新增课程
4. **邮件通知** - 发现新课程立即发送邮件
## 故障排查
### 问题:登录失败
**解决:**
1. 检查 `config.ini` 中的用户名密码
2. 手动登录网页版确认账号正常
3. 查看 `.debug_response.html` 了解实际响应
### 问题:邮件发送失败
**解决:**
1. 确认使用SMTP授权码不是邮箱密码
2. 检查163邮箱是否开启SMTP服务
3. 查看 `monitor.log` 了解错误详情
### 问题:提示"请不要过快点击"
**解决:**
- 程序会自动增加等待时间
- 可在 `config.ini` 中增大 `CHECK_INTERVAL`
## 配置说明
```ini
[monitor]
CHECK_INTERVAL = 60 # 检查间隔(秒)
REQUEST_DELAY = 5 # 请求延迟(秒)
MAX_RETRIES = 3 # 重试次数
RETRY_DELAY = 10 # 重试间隔(秒)
```
## 停止监控
```bash
# 前台运行时按 Ctrl+C
# tmux中
tmux attach -t grade_monitor
# 然后按 Ctrl+C
```
## 注意事项
⚠️ **请勿过于频繁地检查** - 建议检查间隔不小于60秒
⚠️ **保护好配置文件** - 包含账号密码,不要上传到公共仓库
⚠️ **授权码不是密码** - 163邮箱需要单独获取SMTP授权码
## 许可证
MIT License