155 lines
5.0 KiB
Bash
155 lines
5.0 KiB
Bash
#!/bin/bash
|
|
# 快速修复成绩提取失败问题
|
|
|
|
echo "========================================="
|
|
echo "成绩监控系统 - 故障诊断与修复工具"
|
|
echo "========================================="
|
|
echo ""
|
|
|
|
cd ~/grade_monitor || cd "$(dirname "$0")"
|
|
|
|
# 1. 检查 BeautifulSoup 安装
|
|
echo "1. 检查依赖库..."
|
|
if python3 -c "import bs4" 2>/dev/null; then
|
|
echo " ✓ BeautifulSoup4 已安装"
|
|
else
|
|
echo " ✗ BeautifulSoup4 未安装,正在安装..."
|
|
pip3 install beautifulsoup4
|
|
fi
|
|
|
|
if python3 -c "import requests" 2>/dev/null; then
|
|
echo " ✓ requests 已安装"
|
|
else
|
|
echo " ✗ requests 未安装,正在安装..."
|
|
pip3 install requests
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# 2. 运行测试模式
|
|
echo "2. 运行诊断测试..."
|
|
echo " 执行: python3 monitor.py --test --debug"
|
|
echo "========================================="
|
|
python3 monitor.py --test --debug 2>&1 | tee test_output.log
|
|
echo "========================================="
|
|
echo ""
|
|
|
|
# 3. 检查输出
|
|
echo "3. 分析测试结果..."
|
|
|
|
if grep -q "找到成绩表格" test_output.log; then
|
|
echo " ✓ 成功找到成绩表格"
|
|
else
|
|
echo " ✗ 未找到成绩表格"
|
|
fi
|
|
|
|
if grep -q "共解析到.*门课程" test_output.log; then
|
|
COURSE_COUNT=$(grep "共解析到.*门课程" test_output.log | tail -1 | grep -oP '\d+')
|
|
if [ "$COURSE_COUNT" -gt 0 ]; then
|
|
echo " ✓ 成功解析 $COURSE_COUNT 门课程"
|
|
else
|
|
echo " ✗ 解析到 0 门课程"
|
|
fi
|
|
else
|
|
echo " ✗ 无法解析课程信息"
|
|
fi
|
|
|
|
if grep -q "检测到登录页面\|LOGIN_REQUIRED" test_output.log; then
|
|
echo " ⚠ 检测到登录失败,可能需要检查账号密码"
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# 4. 检查调试文件
|
|
echo "4. 检查生成的调试文件..."
|
|
if [ -f "debug_page.html" ]; then
|
|
echo " ✓ 发现 debug_page.html"
|
|
FILE_SIZE=$(stat -f%z "debug_page.html" 2>/dev/null || stat -c%s "debug_page.html" 2>/dev/null)
|
|
echo " 文件大小: $FILE_SIZE 字节"
|
|
|
|
if grep -qi "gridtable\|dataList" debug_page.html; then
|
|
echo " ✓ HTML 中包含成绩表格标签"
|
|
else
|
|
echo " ✗ HTML 中未找到预期的表格标签"
|
|
echo " 建议: 手动检查 debug_page.html 文件"
|
|
fi
|
|
fi
|
|
|
|
if [ -f ".last_grade_content.txt" ]; then
|
|
echo " ✓ 发现 .last_grade_content.txt"
|
|
LINES=$(wc -l < .last_grade_content.txt)
|
|
echo " 内容行数: $LINES"
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# 5. 提供建议
|
|
echo "5. 修复建议:"
|
|
echo "========================================="
|
|
|
|
if ! python3 -c "import bs4" 2>/dev/null; then
|
|
echo "❌ 缺少 beautifulsoup4 库"
|
|
echo " 修复: pip3 install beautifulsoup4"
|
|
echo ""
|
|
fi
|
|
|
|
if grep -q "共解析到 0 门课程" test_output.log; then
|
|
echo "❌ 无法解析课程信息"
|
|
echo " 可能原因:"
|
|
echo " 1. 登录失效 - 检查 config.ini 中的账号密码"
|
|
echo " 2. 网页结构变化 - 查看 debug_page.html"
|
|
echo " 3. 网络问题 - 检查是否能访问学校网站"
|
|
echo " 4. 临时性问题 - 程序会自动重试"
|
|
echo ""
|
|
echo " 下一步:"
|
|
echo " - 查看详细日志: cat test_output.log"
|
|
echo " - 查看HTML: cat debug_page.html | head -50"
|
|
echo " - 阅读排查指南: cat 故障排查指南.md"
|
|
echo ""
|
|
fi
|
|
|
|
# 检查间歇性错误
|
|
if [ -f "monitor.log" ]; then
|
|
FAILED_COUNT=$(grep -c "未找到成绩表格\|共解析到 0 门课程" monitor.log 2>/dev/null || echo "0")
|
|
SUCCESS_COUNT=$(grep -c "共解析到 [1-9]" monitor.log 2>/dev/null || echo "0")
|
|
|
|
if [ "$FAILED_COUNT" -gt 0 ] && [ "$SUCCESS_COUNT" -gt 0 ]; then
|
|
FAILURE_RATE=$((FAILED_COUNT * 100 / (FAILED_COUNT + SUCCESS_COUNT)))
|
|
echo "⚠️ 检测到间歇性解析失败"
|
|
echo " 成功次数: $SUCCESS_COUNT"
|
|
echo " 失败次数: $FAILED_COUNT"
|
|
echo " 失败率: ${FAILURE_RATE}%"
|
|
echo ""
|
|
if [ "$FAILURE_RATE" -lt 20 ]; then
|
|
echo " ✓ 失败率较低(<20%),属于正常范围"
|
|
echo " 原因: 网络波动或服务器临时问题"
|
|
echo " 处理: 程序已自动重试,无需干预"
|
|
else
|
|
echo " ✗ 失败率偏高(>20%),需要检查"
|
|
echo " 建议: 检查网络连接和登录状态"
|
|
fi
|
|
echo ""
|
|
fi
|
|
fi
|
|
|
|
if grep -q "找到.*行成绩数据" test_output.log && grep -q "共解析到.*门课程" test_output.log; then
|
|
COURSE_COUNT=$(grep "共解析到.*门课程" test_output.log | tail -1 | grep -oP '\d+')
|
|
if [ "$COURSE_COUNT" -gt 0 ]; then
|
|
echo "✅ 系统工作正常!"
|
|
echo " 成功解析了 $COURSE_COUNT 门课程"
|
|
echo ""
|
|
echo " 如果服务未运行,启动服务:"
|
|
echo " systemctl start grade-monitor"
|
|
echo ""
|
|
echo " 查看服务状态:"
|
|
echo " systemctl status grade-monitor"
|
|
echo ""
|
|
fi
|
|
fi
|
|
|
|
echo "========================================="
|
|
echo ""
|
|
echo "测试日志已保存到: test_output.log"
|
|
echo "如需帮助,请查看: 故障排查指南.md"
|
|
echo ""
|