From a75444a93180c77d3681543f6893ffd8d61e431e Mon Sep 17 00:00:00 2001 From: JesterHey Date: Mon, 11 Mar 2024 14:13:42 +0800 Subject: [PATCH] modified: __pycache__/get_info.cpython-310.pyc modified: __pycache__/kill_course.cpython-310.pyc modified: __pycache__/single_course.cpython-310.pyc modified: course_info.json modified: demo.py modified: get_info.py modified: kill_course.py modified: main.py modified: single_course.py --- __pycache__/get_info.cpython-310.pyc | Bin 1683 -> 2392 bytes __pycache__/kill_course.cpython-310.pyc | Bin 1193 -> 1304 bytes __pycache__/single_course.cpython-310.pyc | Bin 2318 -> 2689 bytes course_info.json | 158 +--------------------- demo.py | 14 +- get_info.py | 70 +++++++--- kill_course.py | 5 +- main.py | 50 +++++-- single_course.py | 23 ++-- 9 files changed, 114 insertions(+), 206 deletions(-) diff --git a/__pycache__/get_info.cpython-310.pyc b/__pycache__/get_info.cpython-310.pyc index 4993b548da6cadefd6a9a5f777cf0b0e06b0092f..4c586a4ae704c7786b4a7b57755e0935753accec 100644 GIT binary patch literal 2392 zcmZWr|Bo9-72lbiU9Z<`pL3Vy3q>O0L>2dk`_^7Vj|QFE@LP3?nn&(vP&dXW~m=d79076J0O698>(V`Yq#FwZc=_QgXgbauh5_4$jCgv})QeT5r`Zd*R znhb{M*){0RAZj)lzn&W#K95BM$%&IkMs7iS1zIe?l4&tScTE#o zU+batRE9PYMHEwg2lKN64|Ga)A+y&Zr)$uM6`~2!eFi}+NKEZ;&p*FC(qY1faJ#~9vnUbCQy>o?{bcz4ozdbGpB()Dep;MOV#e3JHgl(!7Z;yjSXx?GScdn~ ziwlci2Xn`ZZTHUhtK z^Kzr*U96=S<&pU9=IUxJx&gbq+If7$=wt?|+1W~VD!QJC7Z00lp+!+yzmSg*VlTSZ=^5Em)<9@Bm zG1zmR1&m9KtRdnXjjk8gTM>`h4G6F`Ekb{tvMLO=^-f6|sC3>T66W0%clX0!9)EQc%_6vj7VsfqFtKDFaA{k{vuS zrOnrRm>NA@0L1&~iuR4ydIZ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K&ZNm;9SHJM}JAJU!nuYE-+bdMj&aY1D)8Rx825Q}Az1+?N fZ20yh6UA752!9>QEl(G5{J(TDr~Lf@v;Up}pg#Vp diff --git a/__pycache__/kill_course.cpython-310.pyc b/__pycache__/kill_course.cpython-310.pyc index 487713a60477d256d99c515482c8bb4ada65a6fc..d479e032202b4ada7e74886f30fe312068ae147a 100644 GIT binary patch delta 770 zcma)4zl#$=6n<}Zc6WA@oC^wO#YPlDNMWG}ViVN6&LUhRqJ-Q{BFCBRIawQ>B?l2S z{=#D$5tU6LXro|bCtPFWf3U42T8aOGzDY!)aBwqxeEZ(a_r13>^VWOj*P>F%2O7(- zezbQTfUhQ49GrqWp})3Mt5*urZF?Oih4k*)SNwKC`kPFhZ2Ln%kk;x9)#A>BQ-hV< zZe4F}^wx2~&eWnRaKSh}ry_J|!~pV%cX z5DRVh8`>eb1fjlYTXnUa`C~}DnNyMMJy{B2ULh{bBPocNLeL-&Jmv!`?WmD<_8~NO ze}$xT)obnUL+Age6KYqBKe}ae5PNlMI$kXJ&mZ?2=9CPoL3)W*j@@Q=l3QiEvFT`g z`eO9`{iknl9!_4~n|%B*dG}~~|7jYthCpR5wpvU-v(q(Y(|67{dYveDI+5zO;@sMb zwv>5JRe!cMx7K^HI+#|hCztD#7A#-^7V!wO?EpFY1i=KFX<~tgu)HUif2yOVrf4?1 j^y-?;Dy~p7oS(s^^c+9o~V2&eAA{JJn*9S=_(LT;WvYMis|WkGJVSN6!-K)7+ilgdp;)K8T#FCcZ?UB)=Y53Y@d@mf Bi0l9W diff --git a/__pycache__/single_course.cpython-310.pyc b/__pycache__/single_course.cpython-310.pyc index d41db2265b3f5db4b99e4d84f7b5dc7c5220362e..a3b6f98e8fc49523faef7dae1dfc5c01e93a0d9b 100644 GIT binary patch delta 1407 zcmb7E&u<%55PtJ^z58};ZyYDKacE0_fP_`(0T68}Bx2QSuT?7%Q4txFSuDG$P1b7) z(X(uDb7>1nWrQMuge^f&&?0(hQ7iFx;1d#YlOj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Nuv;G0f~6Svr6dcyW&@u}uDk8zei!IN3=lnuVT=z*Gr>5hYrX zroQD*ib&(7&^I`}!8RPaA{<)@3nbRHxkgkqqtv%SL-Ph|p6UWs=_wjgmYv<~Kg!)< z6;5OHY#MYj@qho%Sgi+?2-tJl)q48mW!>Om?LnA6ccnfBjJZ>^zL?)QcP-9TZA;aQ*f1J$iAujHD;W+SB4=JSHQwmEo(GcKfSXTB4tVN$*@`Xm{jRD}KIM zt;=oSCVP96lob~|2?F|(02h*6w4XZj50m^*F<{Jx4;J;kKd;G-wEpLRh zBA?$XtXJ~+RrA)u!ki3$iQ{EbIk$c4 + elif page.ele('tag:img@@style=width: 25px;height: 25px;',timeout=3): + page.ele('tag:img@@style=width: 25px;height: 25px;').click() + except BaseException: + logger.error('不能进入课程页面') + subprocess.run(["python", __file__]) + exit() + page.ele('#login_btn').click() + page.ele('@value=进入个人中心').click() +def get_info(first:bool=True): + # 创建页面对象,并启动或接管浏览器 + page = WebPage() + # 登录 + login(first) # 提取课程信息 time.sleep(2) - page.ele('@value=0').click() + if not first: + page.refresh() + time.sleep(2) + page.ele('@value=0',timeout=3).click() # 获取总页数 course_info = {} #
1 / 4
diff --git a/kill_course.py b/kill_course.py index 48f8aad..2444f02 100644 --- a/kill_course.py +++ b/kill_course.py @@ -12,7 +12,10 @@ def kill_course(again:bool=False): for k, v in info.items(): if v['rate'] < 100: cnt[v['type']].append((k,v['rate'])) # 课程类型作为键,课程id作为值 - print(cnt) + logger.info('{}'.format(cnt)) + if not cnt: + logger.info('所有课程均已完成') + return # 按必修-选秀-专题-培训执行刷课 must = cnt['必修'] elective = cnt['选修'] diff --git a/main.py b/main.py index e7644b9..ae08881 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,9 @@ from collections import * from loguru import logger import subprocess from typing import * +from DrissionPage import ChromiumPage +from DrissionPage.common import * +import time # 获取课程信息 get_info() # 执行刷课 @@ -15,11 +18,10 @@ kill_course() 1. 对于必修课存在3种情况:未完成,已完成,未答题 2. 对于其他课存在3种情况:未完成,已完成,未评分 ''' - # 重新获取课程信息 def new_info() -> DefaultDict[str, List[Tuple[str,int,str]]]: - get_info() - new_info = json.load(open('info.json','r')) + get_info(first=False) + new_info = json.load(open('course_info.json','r')) # 读取各个类别的课程状态 new_cnt = defaultdict(list) for k, v in new_info.items(): @@ -42,20 +44,44 @@ new_cnt = new_info() not_judged = [] not_quiz = [] for k, v in new_cnt.items(): - if v['status'] == '已完成': - continue - if v['status'] == '未评分': - not_judged.append(k) - else: - not_quiz.append(k) + for i in v: + if i[2] == '未评分': + not_judged.append((i[0],k)) + elif i[2] == '未答题': + not_quiz.append(i[0],k) # 展示提示信息 for i in not_judged: logger.warning('存在未评分的课程:{}'.format(i)) # 实现自动评分 -def auto_judge(course_id:str) -> None: +def auto_judge(course_id:str,course_type:str) -> None: + # 根据课程类型和id进行定位 + j_page = ChromiumPage() # 接管当前页面 + # 判定课程类别 + if course_type == '必修': + j_page.ele('@value=1').click() + elif course_type == '选修': + j_page.ele('@value=2').click() + elif course_type == '专题': + j_page.ele('@value=4').click() + elif course_type == '培训': + j_page.ele('@value=5').click() + time.sleep(1) + trs = j_page.ele('#tbody').eles('tag:tr') + for tr in trs: + # 鉴别课程序号 + if tr.ele('tag:td').text.split('\t')[0] == course_id: + # 进入评分页面 + tr.ele('tag:button@@text():进入评分').click() + j_page.ele('x://*[@id="gradeDetail_score"]/label[1]/input').click() + j_page.ele('tag:a@@text():保存').click() + time.sleep(1) pass +print(not_judged) +# 实现自动评分 for i in not_judged: - logger.warning('存在未答题的课程:{}'.format(i)) + auto_judge(i[0],i[1]) + logger.info('已完成对课程:{}的评分'.format(i[0])) # 实现自动答题 -pass \ No newline at end of file +def auto_quiz(course_id:str) -> None: + pass \ No newline at end of file diff --git a/single_course.py b/single_course.py index 170db38..e1db538 100644 --- a/single_course.py +++ b/single_course.py @@ -82,17 +82,18 @@ def one_course(cid:str,ctype:str,crate:int,again:bool=False): tab.ele('tag:a@@text():是').click() except: pass - # 有时候没有弹窗提示,用以下方式手动检测 - for i in l: - if i != 100: - tab.ele('#normalModel_nodeList').eles('tag:div')[l.index(i)].click() - time.sleep(1) - try: - if tab.ele('c:#normalModel_video > xg-start > div.xgplayer-icon-play > svg > path',timeout=2): - tab.ele('c:#normalModel_video > xg-start > div.xgplayer-icon-play > svg > path').click() - except: - pass - time.sleep(60) # 每次监测间隔60秒 + finally: + # 有时候没有弹窗提示,用以下方式手动检测 + for i in l: + if i != 100: + tab.ele('#normalModel_nodeList').eles('tag:div')[l.index(i)+1].click() + time.sleep(1) + try: + if tab.ele('c:#normalModel_video > xg-start > div.xgplayer-icon-play > svg > path',timeout=2): + tab.ele('c:#normalModel_video > xg-start > div.xgplayer-icon-play > svg > path').click() + except: + pass + time.sleep(60) # 每次监测间隔60秒 break # なぜここにbreakがいるのですか?あかしいなあ。 if __name__ == '__main__':