diff --git a/__pycache__/single_course.cpython-310.pyc b/__pycache__/single_course.cpython-310.pyc index 96130b2..d41db22 100644 Binary files a/__pycache__/single_course.cpython-310.pyc and b/__pycache__/single_course.cpython-310.pyc differ 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()