This commit is contained in:
NianBroken
2024-01-21 22:31:43 +08:00 Unverified
commit 69430da965
23 changed files with 1858 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
name: CheckScores
on:
schedule:
- cron: "*/30 * * * *" # 每30分钟执行一次
workflow_dispatch: # 允许手动触发workflow
jobs:
CheckScores:
runs-on: ubuntu-latest # 在最新版的Ubuntu系统上运行
steps:
- name: Checkout Repository # 使用GitHub Actions提供的动作来检出代码库
uses: actions/checkout@v2
- name: Set up Python # 配置Python环境
uses: actions/setup-python@v2
with:
python-version: 3.x # 使用Python 3.x版本
- name: Install dependencies # 使用pip安装项目的依赖项
run: |
pip install requests rsa pyquery
- name: Configure Git # 配置Git用户信息
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
- name: Fetch upstream changes # 添加上游仓库作为远程仓库,并获取上游仓库的main分支的最新更改
run: |
git remote add upstream https://github.com/NianBroken/ZFCheckScores.git
git fetch upstream main
- name: Backup local .txt files # 创建一个备份目录,并将当前目录中的所有.txt文件复制到备份目录
run: |
mkdir backup
cp *.txt backup/
- name: Force push changes from upstream to current main branch # 将上游main分支的更改强制推送到当前main分支
run: |
git checkout main
git reset --hard upstream/main
git push origin main --force
- name: Restore local .txt files and delete backup # 从备份目录将.txt文件还原到当前目录,然后删除备份目录
run: |
cp backup/*.txt .
rm -rf backup
- name: Run main.py # 运行主程序main.py
run: python main.py
env:
URL: ${{ secrets.URL }}
USERNAME: ${{ secrets.USERNAME }}
PASSWORD: ${{ secrets.PASSWORD }}
TOKEN: ${{ secrets.TOKEN }}
- name: Add changes # 将当前目录中的所有更改添加到Git的暂存区
run: |
git add .
- name: Commit changes # 提交更改到Git仓库
run: |
git commit -m "Update from GitHub Actions" || true # 如果没有更改,则允许提交失败,但不中断workflow
- name: Force push changes to main branch # 将更改强制推送到main分支
run: |
git push origin main --force
+95
View File
@@ -0,0 +1,95 @@
# 正方教务系统成绩推送
## 作用
**使用本项目前:**
睡醒看一遍教务系统、上厕所看一遍教务系统、刷牙看一遍教务系统、洗脸看一遍教务系统、吃早餐看一遍教务系统、吃午饭看一遍教务系统、睡午觉前看一遍教务系统、午觉醒来看一遍教务系统、吃完晚饭看一遍教务系统、洗澡看一遍教务系统、睡觉之前看一遍教务系统。
**使用本项目后:**
成绩更新后自动发通知到微信 以节省您宝贵的时间
## 测试环境
正方教务系统 版本 V8.0.0
## 目前支持的功能
1. 每隔 30 分钟自动检测成绩是否更新 若更新则向微信推送通知
2. 显示成绩提交时间(何时将成绩录入教务系统)
3. 显示成绩提交人姓名(何人将成绩录入教务系统)
## 使用方法
### 1. Fork 本仓库
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/1.png" style="zoom:40%;" />
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/2.png" style="zoom:40%;" />
### 2. 开启工作流读写权限
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/3.png" style="zoom:40%;" />
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/4.png" style="zoom:40%;" />
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/5.png" style="zoom:40%;" />
### 3. 添加 Secrets
| Name | 例子 | 说明 |
| -------- | -------------------------- | ----------------- |
| URL | https://www.nianbroken.top | 教务系统地址 |
| USERNAME | 2971802058 | 教务系统用户名 |
| PASSWORD | Y3xhaCkb5PZ4 | 教务系统密码 |
| TOKEN | J65KWMBfyDh3YPLpcvm8 | Pushplus 的 token |
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/6.png" style="zoom:40%;" />
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/7.png" style="zoom:40%;" />
获取 TOKEN
- [登录 Pushplus ](https://www.pushplus.plus/login.html)
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/17.png" style="zoom:40%;" />
- [获取 Token](https://www.pushplus.plus/api/open/user/token)
打开页面后,你会得到一个类似下列所示的 Json 代码块,`data`中的值就是 TOKEN
```json
{
"code": 200,
"msg": "请求成功",
"data": "cd735c356aa14d16b1452aa932ac89cc",
"count": null
}
```
- [相关文档](https://www.pushplus.plus/doc/guide/openApi.html#_1-%E8%8E%B7%E5%8F%96token)
当你的 Secrets 添加完成后,你的页面应该是类似下图所示
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/8.png" style="zoom:40%;" />
### 4. 开启 Actions
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/9.png" style="zoom:40%;" />
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/10.png" style="zoom:40%;" />
### 5. 运行程序
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/11.png" style="zoom:40%;" />
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/12.png" style="zoom:40%;" />
当你的页面应该是类似下图所示时则表示程序运行结束且未报错
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/13.png" style="zoom:40%;" />
在此之后 程序将会每隔 30 分钟自动运行一次
### 6. 查看运行结果
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/14.png" style="zoom:40%;" />
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/15.png" style="zoom:40%;" />
### 7. 成绩更新通知
当检测到成绩更新时,你的页面应该是类似下图所示
<img src="https://cdn.jsdelivr.net/gh/NianBroken/ZFCheckScores/img/16.png" style="zoom:40%;" />
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 183 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

+143
View File
@@ -0,0 +1,143 @@
import base64
import hashlib
import os
import sys
from pprint import pprint
from zfn_api import Client
from pushplus import send_message
# 教务系统的URL、用户名和密码
url = os.environ.get("URL")
username = os.environ.get("USERNAME")
password = os.environ.get("PASSWORD")
# 定义一个md5加密的封装函数
def md5_encrypt(string):
# 将字符串转换为字节
byte_string = string.encode()
# 创建一个MD5对象
md5_object = hashlib.md5(byte_string)
# 返回MD5加密后的十六进制字符串
return md5_object.hexdigest()
# 初始化相关变量
cookies = {} # 初始化cookies为空字典
base_url = url
raspisanie = []
ignore_type = []
detail_category_type = []
timeout = 5
stu = Client(
cookies=cookies,
base_url=base_url,
raspisanie=raspisanie,
ignore_type=ignore_type,
detail_category_type=detail_category_type,
timeout=timeout,
)
# 如果cookies为空字典,则进行登录
if not cookies:
lgn = stu.login(username, password)
if lgn["code"] == 1001:
verify_data = lgn["data"]
# 将验证码保存为图片文件
with open(os.path.abspath("kaptcha.png"), "wb") as pic:
pic.write(base64.b64decode(verify_data.pop("kaptcha_pic")))
verify_data["kaptcha"] = input("输入验证码:")
ret = stu.login_with_kaptcha(**verify_data)
if ret["code"] != 1000:
pprint(ret)
sys.exit()
pprint(ret)
elif lgn["code"] != 1000:
pprint(lgn)
sys.exit()
# 获取个人信息
info = stu.get_info()["data"]
# 整合个人信息
integrate_info = (
f"个人信息:\n" f"学号:{info['sid']}\n" f"班级:{info['class_name']}\n" f"姓名:{info['name']}"
)
# 获取成绩信息
firstrun_file_path = "firstrun.txt"
# 如果firstrun.txt文件不存在,创建并写入true
if not os.path.exists(firstrun_file_path):
with open(firstrun_file_path, "w") as firstrun_file:
firstrun_file.write("true")
# 第一次运行则运行两遍,否则运行一遍
run_count = 2 if open(firstrun_file_path).read() == "true" else 1
for _ in range(run_count):
# 如果grade.txt文件不存在,创建文件
if not os.path.exists("grade.txt"):
open("grade.txt", "w").close()
# 清空old_grade.txt文件内容
with open("old_grade.txt", "w"):
pass
# 将grade.txt文件中的内容写入到old_grade.txt文件内。
with open("grade.txt", "r") as grade_file, open(
"old_grade.txt", "w"
) as old_grade_file:
old_grade_file.write(grade_file.read())
# 清空grade.txt文件内容
with open("grade.txt", "w"):
pass
# 将下列代码输出的所有内容都写入到grade.txt文件内。
integrated_grade_info = "成绩信息:"
grade = stu.get_grade(2023)["data"]["courses"]
for course in grade:
# 整合成绩信息
integrated_grade_info += (
f"\n课程ID: {course['course_id']}\n"
f"课程名称: {course['title']}\n"
f"任课教师: {course['teacher']}\n"
f"成绩: {course['grade']}\n"
f"提交时间: {course['submission_time']}\n"
f"提交人姓名: {course['name_of_submitter']}\n"
f"------"
)
# 加密保存成绩
encrypt_integrated_grade_info = md5_encrypt(integrated_grade_info)
# 将加密后的成绩信息写入grade.txt文件
with open("grade.txt", "w") as grade_file:
grade_file.write(encrypt_integrated_grade_info)
# 对grade.txt和old_grade.txt两个文件的内容进行比对
with open("grade.txt", "r") as grade_file, open("old_grade.txt", "r") as old_grade_file:
# 读取grade.txt和old_grade.txt文件的内容
grade_content = grade_file.read()
old_grade_content = old_grade_file.read()
# 输出成绩信息
print(f"新成绩:{encrypt_integrated_grade_info}")
print(f"旧成绩:{old_grade_content}")
print("------")
# 整合所有信息
integrate_send_info = f"{integrate_info}\n------\n{integrated_grade_info}"
# 输出成绩是否更新
if grade_content == old_grade_content:
print("成绩未更新")
else:
print("成绩已更新")
response_text = send_message("教务成绩已更新", integrate_send_info)
print(response_text)
# 更新firstrun.txt文件内容为false
if open(firstrun_file_path).read() == "true":
with open(firstrun_file_path, "w") as firstrun_file:
# 将firstrun.txt文件内容更新为false
firstrun_file.write("false")
+14
View File
@@ -0,0 +1,14 @@
import requests
import json
import os
def send_message(title, content):
token = os.environ.get("TOKEN")
url = "http://www.pushplus.plus/send"
data = {"token": token, "title": title, "content": content}
body = json.dumps(data).encode(encoding="utf-8")
headers = {"Content-Type": "application/json"}
response = requests.post(url, data=body, headers=headers)
return response.text
View File
+1537
View File
File diff suppressed because it is too large Load Diff