From 29becd59a81a9fbcb7758d12b9467038987ff343 Mon Sep 17 00:00:00 2001 From: JesterHey Date: Sun, 10 Mar 2024 14:17:56 +0800 Subject: [PATCH] modified: __pycache__/single_course.cpython-310.pyc modified: course_info.json modified: kill_course.py modified: main.py modified: single_course.py --- __pycache__/single_course.cpython-310.pyc | Bin 2148 -> 2318 bytes course_info.json | 2 +- kill_course.py | 10 +++--- main.py | 36 ++++++++++++++++++++++ single_course.py | 5 ++- 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/__pycache__/single_course.cpython-310.pyc b/__pycache__/single_course.cpython-310.pyc index 96130b22d72f3adfc9aaaa18a2954307240241a0..d41db2265b3f5db4b99e4d84f7b5dc7c5220362e 100644 GIT binary patch delta 497 zcmYjMO-my|5bf$@K1eblI~WsPH7bbYpeVb7pp1yJcvw*IAPO=_I!e|t8Sr@;H0;OAM5{4guY0QpqUDC z;RiMlnj$4vXhHjnc^50mIvp#eMVgtr2^`D|6-|o~gbEvsKI6iADD6sO@IjFh3B@B?0^Z8|>DhS~+;dHJAznVNNKeo%4u_AM(mid~E3V8E?c z?TXvresz4-aVuMnZ=rZ;y*^hofQ-CS7sfV}T7BDfco$Cc{3~^%YNy_8G|YWRe%0n^ z7UZ#3);jb)`JYe9pW4#Q$GBT{+?@t*@c38UjA=Bc$+)K5c71EFYTNHtJTL2(mOi8` I=OFp`1f&vt4gdfE delta 325 zcmeAZdLqD^&&$ij00fte-=;E8`C8%(_0CV!=twT5*8V+zkg#w@l4 z>?ynp8B_Qq8EP1^nID8sanfsrAcq3{kPkY;3v z1hNY6lrS$~Ns(X3$jDGQvCuI^Dwsi2VY34BB&N+ZZ0wAT+>=|_o!M_OX0Bu?(w@x7 z<|dGzml~g(Us_b0$`0~I*5ohj_LEIHG})gpy=D1Vq&qp4!^2txD0Pc1CqKQksI-U$ r#9=NjDJoI`vWj#;T#oqoyu{qp`1m4ikQjo{nf!u7k=0Ltk>x)CW3N}N diff --git a/course_info.json b/course_info.json index 289ca3c..939ed27 100644 --- a/course_info.json +++ b/course_info.json @@ -1 +1 @@ -{"6349": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7436": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7367": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7366": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7033": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7517": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7032": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7516": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7031": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7515": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "6937": {"rate": 0, "type": "\u57f9\u8bad", "status": "\u672a\u5b66\u5b8c"}, "6938": {"rate": 0, "type": "\u57f9\u8bad", "status": "\u672a\u5b66\u5b8c"}, "6991": {"rate": 9, "type": "\u57f9\u8bad", "status": "\u672a\u5b66\u5b8c"}, "6992": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "6993": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "6995": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7006": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7007": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7010": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7011": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7554": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7553": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7552": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7551": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7550": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7549": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7548": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7547": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7546": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7545": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7564": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}} \ No newline at end of file +{"7367": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7366": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7033": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7517": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7032": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7516": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7031": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7515": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "6349": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7436": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "6937": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u672a\u8bc4\u5206"}, "6938": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u672a\u8bc4\u5206"}, "6991": {"rate": 15, "type": "\u57f9\u8bad", "status": "\u672a\u5b66\u5b8c"}, "6992": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "6993": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "6995": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7006": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7007": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7010": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7011": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7554": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7553": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7552": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7551": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7550": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7549": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7548": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7547": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7546": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7545": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7564": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}} \ No newline at end of file diff --git a/kill_course.py b/kill_course.py index 1d20ba7..48f8aad 100644 --- a/kill_course.py +++ b/kill_course.py @@ -4,7 +4,7 @@ from collections import * import json from single_course import one_course from loguru import logger -def kill_course(): +def kill_course(again:bool=False): # 统计课程完成情况 cnt = defaultdict(list) # 读取课程信息 @@ -22,19 +22,19 @@ def kill_course(): if must: course_info = must.pop() logger.info('当前刷课序号:{}'.format(course_info[0])) - one_course(course_info[0], '必修', course_info[1]) + one_course(course_info[0], '必修', course_info[1], again=again) if elective: course_info = elective.pop() logger.info('当前刷课序号:{}'.format(course_info[0])) - one_course(course_info[0], '选修', course_info[1]) + one_course(course_info[0], '选修', course_info[1],again=again) if special: course_info = special.pop() logger.info('当前刷课序号:{}'.format(course_info[0])) - one_course(course_info[0], '专题', course_info[1]) + one_course(course_info[0], '专题', course_info[1],again=again) if train: course_info = train.pop() logger.info('当前刷课序号:{}'.format(course_info[0])) - one_course(course_info[0], '培训', course_info[1]) + one_course(course_info[0], '培训', course_info[1],again=again) if __name__ == '__main__': kill_course() \ No newline at end of file diff --git a/main.py b/main.py index 147a23e..82ce4b5 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,42 @@ +import json from get_info import get_info +from collections import * +from loguru import logger +import subprocess +from typing import * # 获取课程信息 get_info() # 执行刷课 from kill_course import kill_course kill_course() +# 完成刷课后,判定是否存在需要答题或者评分的课程 +''' +重新检测各个课程的status参数 +1. 对于必修课存在3种情况:未完成,已完成,未答题 +2. 对于其他课存在3种情况:未完成,已完成,未评分 +''' + +# 重新获取课程信息 +def new_info() -> DefaultDict[str, List[Tuple[str,int,str]]]: + get_info() + new_info = json.load(open('info.json','r')) + # 读取各个类别的课程状态 + new_cnt = defaultdict(list) + for k, v in new_info.items(): + new_cnt[v['type']].append((k,v['rate'],v['status'])) # 课程类型作为键,课程id作为值 + return new_cnt + +new_cnt = new_info() +# 首先检查是否还存在未完成的课程 +for k, v in new_cnt.items(): + for i in v: + if i[1] < 100: + logger.critical('存在未完成的课程:{}! 将重新执行刷课'.format(i[0])) + # 完全关闭进程并重新执行刷课 + kill_course(again=True) + subprocess.run(["python", __file__]) + exit() + +# 若上述检验通过,则重新读取课程信息并检验是否存在未答题或者未评分的课程 +new_cnt = new_info() +# 睡午觉了,下午写吧,哈哈 diff --git a/single_course.py b/single_course.py index 0701a41..2f699bf 100644 --- a/single_course.py +++ b/single_course.py @@ -4,7 +4,7 @@ import time from loguru import logger # 实现单个课程的刷课逻辑 -def one_course(cid:str,ctype:str,crate:int): +def one_course(cid:str,ctype:str,crate:int,again:bool=False): ''' cid: 课程id ctype: 课程类型 @@ -18,6 +18,9 @@ def one_course(cid:str,ctype:str,crate:int): ''' # 接管浏览器 cur_page = ChromiumPage() + if again: + # 关闭所有标签页和浏览器 + cur_page.close() # 判定课程类别 if ctype == '必修': cur_page.ele('@value=1').click()