Skip to content

Commit

Permalink
修正了出现新成绩时的成绩提示,修改了部分文案
Browse files Browse the repository at this point in the history
  • Loading branch information
pkmq24 committed Jun 28, 2021
1 parent 3de9b88 commit 2e1757b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 38 deletions.
49 changes: 22 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,44 @@
- [x] 服务器&PC运行皆可
- [x] 邮件通知
- [x] 微信推送
- [x] 手机推送(iOS)
- [x] 手机推送(iOS Bark)
- [x] 程序运行错误报警推送 *[邮件+微信+手机]*
- [x] 适配新版成绩系统

> ### 欢迎有想法的朋友和我邮件交流, 包括但不限于功能扩展、设计优化等
## :alien: 待实现

- [ ] 代码重构
- [ ] 对非程序员更友好, 如设计GUI
- [ ] 支持`pip install`, 开箱即用
- [ ] ~~小程序~~
- [ ] 设计为1对多模式, 服务器跑主程序, 用户在web页面提交`username`, `password`等参数即可开始监控

## :blue_heart: 运行配置说明

0. **配置方式**
1. **安装依赖库**:执行 `$ pip install -r requirements.txt`
2. **键入配置**
1.`config.example.ini`更名为`config.ini`
2. 按照文件内要求填写内容
3. **运行**
1. 基础运行:`$ python cqu_grade_monitor.py`
2. 持久化运行:
1. `nohup``输出重定向`

1. 可以跑在服务器上, 注意使用`nuhup``输出重定向`来实现后台持久化运行, 提供参考命令如下:

**`nohup python3 -u cqu_grade_monitor.py > grade.log 2>&1 &`**

- 如果想看实时监控进展, 可以通过`tail -f grade.log`查看;

- 如果想看错误日志, 可以通过`cat error.log`查看;

- 如果想看邮件发送日志, 可以通过`cat mail.log`查看;
**`nohup python3 -u cqu_grade_monitor.py > grade.log 2>&1 &`**

2. 也可以跑在自己的电脑上, `cmd`窗口实时显示, 也可以后台运行, 自行研究一下

3. 需要使用到的库已经放在requirements.txt,分别是`requests``pycryptodome``bs4`, 使用pip安装的可以使用指令

`pip install -r requirements.txt`

注:如果报错`No module named 'Crypto'`,可以参考[这篇文章](https://www.cnblogs.com/fawaikuangtu123/p/9761943.html)的第二条解决办法。
- 如果想看实时监控进展, 可以通过`tail -f grade.log`查看;
- 如果想看错误日志, 可以通过`cat error.log`查看;
- 如果想看邮件发送日志, 可以通过`cat mail.log`查看;
2. `screen` 自行百度使用方法
> 注:如果报错`No module named 'Crypto'`,可以参考[这篇文章](https://www.cnblogs.com/fawaikuangtu123/p/9761943.html)的第二条解决办法。
4. 运行出错警报采用**指数退避方式**推送, 第一个目的是能实现持久警报, 防止看漏消息, 没注意到警报; 第二个目的是避免人在外面, 无法解决问题, 但是一直警报的烦恼;

5. **脚本稳定性有待提升[学校服务器不稳定], 后续会逐渐完善, 请谅解!**
5. **有问题欢迎提`issue`或者联系`[email protected]`**

## :alien: 待实现

6. **有问题欢迎提`issue`或者联系`[email protected]`**
- [ ] 代码重构
- [ ] 对非程序员更友好, 如设计GUI
- [ ] 支持`pip install`, 开箱即用
- [ ] ~~小程序~~
- [ ] 设计为1对多模式, 服务器跑主程序, 用户在web页面提交`username`, `password`等参数即可开始监控


## :warning: 特别声明
- 本仓库发布的项目中涉及的任何脚本,仅用于测试和学习研究,禁止用于商业用途及各种引流或者任何非法目的
Expand Down
26 changes: 17 additions & 9 deletions cqu_grade_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from msgPush import *
from TYRZ.enroll import getScoreJson, getAccessTokenDict
from TYRZ.tyrz import getLoginData

import _thread
if useVpn:
import socket
import socks
Expand All @@ -22,9 +22,11 @@
if not os.path.exists('./logs/error.log'):
with open('./logs/error.log','w', encoding='UTF-8') as f:
f.write('init')
f.write("\n")
if not os.path.exists('./logs/email.log'):
with open('./logs/email.log','w', encoding='UTF-8') as f:
f.write('init')
f.write("\n")
def monitor():
errorCount = 0
ssthresh = 1
Expand All @@ -38,7 +40,7 @@ def monitor():
'status': 'success',
'msg': None,
'data': {
'2021春': []
'2021春': [{'id':''}]
},
'code ': None
}
Expand Down Expand Up @@ -69,16 +71,21 @@ def monitor():
#pprint.pprint(new_grade)
else:
grades = new_grade['data'][f'{xn+xq}{words[xq]}']
grades_old = old_grade['data'][f'{xn+xq}{words[xq]}']
old_ids = [i['id'] for i in grades_old]
course_num = len(grades)
delta_course = len(
new_grade['data'][f'{xn+xq}{words[xq]}']) - len(old_grade['data'][f'{xn+xq}{words[xq]}'])
for k in range(delta_course):
new_gr = new_grade['data'][f'{xn+xq}{words[xq]}'][len(old_grade['data'][f'{xn+xq}{words[xq]}'])+k]
new_course = new_gr['courseName']
new_score = new_gr['effectiveScoreShow']
print(strftime("%Y-%m-%d %H:%M:%S", localtime()), end='\t')
print(f"有新成绩了, {new_course}:{new_score}分")
gradePush(new_course, new_score)
for j in range(course_num):
gr_obj = grades[j]
gr_id = gr_obj['id']
if not gr_id in old_ids:
new_course = gr_obj['courseName']
new_score = gr_obj['effectiveScoreShow']
print(strftime("%Y-%m-%d %H:%M:%S", localtime()), end='\t')
print(f"有新成绩了, {new_course}:{new_score}")
_thread.start_new_thread( gradePush,(new_course, new_score))
# gradePush(new_course, new_score)
old_grade = new_grade

except Exception as e:
Expand All @@ -92,6 +99,7 @@ def monitor():
with open('./logs/error.log', 'a', encoding='UTF-8') as f:
f.write(s)
f.write(str(e))
f.write("\n")
print(e)

totalSleepTime += sleepTime
Expand Down
8 changes: 6 additions & 2 deletions msgPush.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def send_email(self):
def send_to_somebody(mailAddress, course, grade):
receivers = [mailAddress]
mail = PersonMail(receivers)
mail.write_msg(f"{course}出成绩啦!", f"您的成绩是: {grade}, 详情请登录 https://my.cqu.edu.cn/sam 查看")
mail.write_msg(f"{course}出成绩啦!", f"您的成绩是: {grade}, 详情请登录 https://my.cqu.edu.cn/sam 查看")
code, result = mail.send_email()
return code, result

Expand Down Expand Up @@ -91,14 +91,16 @@ def gradePush(new_course, new_score):
if(mailCode):
with open('./logs/mail.log', 'a', encoding='UTF-8') as f:
f.write(mailInfo)
f.write("\n")
else:
with open('./logs/error.log', 'a', encoding='UTF-8') as f:
f.write(mailInfo)
f.write("\n")

#! [成绩推送] 微信
if(wechatPush):
title = f"{new_course}出成绩了"
content = f"你的分数是{new_score}"
content = f"你的分数是: {new_score}"
data = {
"text": title,
"desp": content
Expand Down Expand Up @@ -132,6 +134,8 @@ def errorPush():
if(mailCode):
with open('./logs/mail.log', 'a', encoding='UTF-8') as f:
f.write(mailInfo)
f.write("\n")
else:
with open('./logs/error.log', 'a', encoding='UTF-8') as f:
f.write(mailInfo)
f.write("\n")

0 comments on commit 2e1757b

Please sign in to comment.