async def choose_word(course_id: str, task_id: int, task_type: int) -> bool: is_show = not settings.is_multiple_chapter time_out = settings.timeout _logger.i("需要选词", is_show=is_show) res = await requests.get( url=f'https://gateway.vocabgo.com/Student/ClassTask/ChoseWordList?task_id={task_id}' f'&task_type={task_type}×tamp={Tool.time()}&versions={CDR_VERSION}', headers=settings.header, timeout=time_out) json_data = await res.json() res.close() if json_data["code"] == 0 and json_data["msg"].find("开通权限") != -1: raise NoPermission(json_data["msg"]) word_map = {} for word in json_data['data']['word_list']: if word['score'] != 10: tem_str = course_id + ':' + word["list_id"] if word_map.get(tem_str) is None: word_map[tem_str] = [] word_map[tem_str].append(word['word']) if len(word_map) == 0: _logger.i("当前学习任务已完成", is_show=is_show) return True _logger.i(word_map, is_show=False) tem_i = 0 tem_len = 0 for k in word_map: tem_len += len(word_map[k]) while tem_len < 5: tem_o = json_data['data']['word_list'][tem_i] tem_str = course_id + ':' + tem_o["list_id"] if tem_o['word'] not in word_map[tem_str]: if word_map.get(tem_str) is None: word_map[tem_str] = [] word_map[tem_str].append(tem_o['word']) _logger.i(f"单词复选:{tem_o['word']}", is_show=False) tem_i = tem_i + 1 tem_len = 0 for k in word_map: tem_len += len(word_map[k]) _logger.i(word_map, is_show=False) timestamp = Tool.time() sign = Tool.md5(f'task_id={task_id}×tamp={timestamp}&versions={CDR_VERSION}&word_map=' + json.dumps(word_map, separators=(',', ':')).replace("'", '"') + 'ajfajfamsnfaflfasakljdlalkflak') data = { "task_id": task_id, "word_map": word_map, "timestamp": timestamp, "versions": CDR_VERSION, "sign": sign } res = await requests.post( url='https://gateway.vocabgo.com/Student/ClassTask/SubmitChoseWord', headers=settings.header, json=data, timeout=time_out) _logger.i(await res.json(), is_show=False) res.close() _logger.i("选词完毕!", is_show=is_show) return False
def __init__(self): Tool.cls() if settings.user_token != "0" and settings.user_token != "": _logger.i("尝试复用token") res = requests.get( url= 'https://gateway.vocabgo.com/Student/Main?timestamp={}&versions={}' .format(Tool.time(), CDR_VERSION), headers=settings.header) code = res.json()["code"] res.close() if code == 1: _logger.i("授权成功") _logger.i("user_token:" + settings.user_token, is_show=False) return else: _logger.i("曾用token已失效,重新执行授权流程!") Login._generate_qr_code() res = requests.get( url= 'https://gateway.vocabgo.com/Student/Main?timestamp={}&versions={}' .format(Tool.time(), CDR_VERSION), headers=settings.header) code = res.json()["code"] res.close() count = 0 while code != 1: _logger.i("等待授权中......") count = count + 1 time.sleep(5) if count == 6: count = 0 _logger.v("1. 继续等待\n2. 重新生成二维码\n\n0. 返回上一级") code_type = input("请输入指令:") if code_type == "1": continue elif code_type == "2": Login._generate_qr_code() continue elif code_type == "0": return else: sys.exit(0) res = requests.get( url= 'https://gateway.vocabgo.com/Student/Main?timestamp={}&versions={}' .format(Tool.time(), CDR_VERSION), headers=settings.header) code = res.json()["code"] res.close() _logger.i("授权成功") os.remove(f"{CONFIG_DIR_PATH}授权二维码.jpg") settings.save() return
async def verify_answer(self, answer: str, topic_code: str, type_mode: str, task_id: int): timestamp = Tool.time() sign = Tool.md5( f"answer={answer}×tamp={timestamp}&topic_code={topic_code}" + f"&versions={CDR_VERSION}ajfajfamsnfaflfasakljdlalkflak") data = { "answer": answer, "topic_code": topic_code, "timestamp": timestamp, "versions": CDR_VERSION, "sign": sign } res = await requests.post( url=f'https://gateway.vocabgo.com/Student/{type_mode}/VerifyAnswer', json=data, headers=settings.header, timeout=settings.timeout) json_data = await res.json() res.close() if json_data["code"] == 21006: await self.verify_human(task_id) data["timestamp"] = Tool.time() res = await requests.post( url= f'https://gateway.vocabgo.com/Student/{type_mode}/VerifyAnswer', json=data, headers=settings.header, params=data, timeout=settings.timeout) json_data = await res.json() res.close() if json_data['code'] == 10017: _logger.w(f"\n{json_data['msg']}") _logger.w("该限制为词达人官方行为,与作者无关\n按回车退出程序") input() sys.exit(0) if json_data['data']["answer_result"] == 1: pass else: _logger.w(json_data, is_show=False) raise AnswerWrong(data, json_data['data']['topic_code'], json_data['data']["over_status"] != 1) return json_data['data'][ 'topic_code'], json_data['data']["over_status"] != 1
async def skip_answer(topic_code: str, topic_mode: int, type_mode: str) -> dict: time_spent = CDRTask.get_random_time(topic_mode, is_max=True) timestamp = Tool.time() sign = Tool.md5( f"time_spent={time_spent}×tamp={timestamp}&topic_code={topic_code}" + f"&versions={CDR_VERSION}ajfajfamsnfaflfasakljdlalkflak") data = { "topic_code": topic_code, "time_spent": time_spent, "timestamp": timestamp, "versions": CDR_VERSION, "sign": sign } res = await requests.post( url=f'https://gateway.vocabgo.com/Student/{type_mode}/SkipAnswer', json=data, headers=settings.header, timeout=settings.timeout) json = await res.json() res.close() return json
async def skip_learn_task(topic_code: str): is_show = not settings.is_multiple_chapter # 模拟加载流程 _logger.i("正在跳过学习任务的学习阶段", is_show=is_show) timestamp = Tool.time() time_spent = 0 sign = Tool.md5(f"time_spent={time_spent}×tamp={timestamp}&topic_code={topic_code}" f"&versions={CDR_VERSION}ajfajfamsnfaflfasakljdlalkflak") data = { "topic_code": topic_code, "time_spent": time_spent, "timestamp": timestamp, "versions": CDR_VERSION, "sign": sign } res = await requests.post( url='https://gateway.vocabgo.com/Student/ClassTask/SubmitAnswerAndSave', json=data, headers=settings.header, timeout=settings.timeout) json_data = await res.json() res.close() await asyncio.sleep(1) # 流程模拟结束 timestamp = Tool.time() sign = Tool.md5(f"timestamp={timestamp}&topic_code={json_data['data']['topic_code']}" f"&versions={CDR_VERSION}ajfajfamsnfaflfasakljdlalkflak") data = { "topic_code": json_data['data']['topic_code'], "timestamp": timestamp, "versions": CDR_VERSION, "sign": sign } res = await requests.post( url='https://gateway.vocabgo.com/Student/ClassTask/SkipNowTopicMode', json=data, headers=settings.header, timeout=settings.timeout) json_data = await res.json() res.close() return json_data
def task_find_answer(answer: Answer, topic_mode: int, content, remark, options: list, skip_times): # 答案查找 is_skip = None answer_id = None try: if topic_mode == 11: answer_id = answer.find_answer_by_11(content, remark, options, skip_times) elif topic_mode == 13: answer_id = answer.find_answer_by_13(content, remark, options) elif topic_mode == 15 or topic_mode == 16 \ or topic_mode == 21 or topic_mode == 22: answer_id = answer.find_answer_by_15(content.strip(), options) elif topic_mode == 17 or topic_mode == 18: answer_id = answer.find_answer_by_17(content, options) elif topic_mode == 31: answer_id = answer.find_answer_by_31(remark, options) elif topic_mode == 32: answer_id = answer.find_answer_by_32( remark, options, Tool.count_character_in_str("_", content), skip_times) elif topic_mode == 41 or topic_mode == 42: answer_id = answer.find_answer_by_41(content, remark, options) elif topic_mode == 43 or topic_mode == 44: answer_id = answer.find_answer_by_43(content, remark, options) elif topic_mode == 51 or topic_mode == 52: answer_id = answer.find_answer_by_51(content, remark, skip_times) elif topic_mode == 53 or topic_mode == 54: answer_id = answer.find_answer_by_53(content, remark) else: _logger.w(f"未知题型:{topic_mode}") _logger.create_error_txt() input("等待错误检查(按下回车键键即可继续执行)") except AnswerNotFoundException as e: _logger.v("") _logger.w(f"{e}") CDRTask.wait_admin_choose() is_skip = True return answer_id, is_skip
async def run(self): course_id = self.__course_id task_list, json_data = await MyselfTask.get_task_list(course_id) Tool.cls() while True: _logger.v("请输入序号去选择要做的任务:\n") _logger.v(f"{json_data['course_name']}\n当前进度:{json_data['progress']}%\n" + f"累计用时:{Tool.convert_time(json_data['time_spent'])}") for i, task in enumerate(task_list): _logger.v(f"{i + 1:2d}. {task['task_name']:20s} [{task['progress']}%]({task['score']:2.1f}分)") _logger.v("\n#. 以空格分割可一次性选择多个任务") _logger.v(f"#. 你可以在“main{CONFIG_DIR_PATH[1:]}config.txt文件”中修改配置项以控分/修改做题时间间隔等") _logger.v("\n\n0. 选择全部任务\n\n请输入序号:", end="") choose = ' '.join(input("").split()).split(" ") _logger.v(choose, is_show=False) task_choose_list = [] tem_flag = True if CDRTask.check_input_data(choose[0], 0): task_choose_list = task_list else: for c in choose: if not CDRTask.check_input_data(c, len(task_list)): tem_flag = False Tool.cls() _logger.i("输入格式有误!\n") break task_choose_list.append(task_list[int(c) - 1]) if tem_flag: break # 课程单词预处理加载 self._courses_set.add(course_id) course_map = await self.course_pretreatment() Tool.cls() for task in task_choose_list: self._tasks.add_task([ self.do_task(task, course_id, course_map[course_id]) for _ in range(settings.multiple_task) ]) await self.start_task() _logger.i("本次全部任务已完成!") input("按回车键返回上一级")
def do_homework(): Login() URL.load_main() # 模拟加载流程 requests.options("https://app.vocabgo.com/student/", headers=settings.header).close() res = requests.get( "https://gateway.vocabgo.com/Student/Main?timestamp=" f"{Tool.time()}&versions={CDR_VERSION}", headers=settings.header) json = res.json()["data"] res.close() # 模拟加载流程 requests.get( "https://gateway.vocabgo.com/Student/Contest/List?timestamp=" f"{Tool.time()}&versions={CDR_VERSION}", headers=settings.header).close() timestamp = Tool.time() sign = Tool.md5( f'return_url=https%3A%2F%2Fapp.vocabgo.com%2Foverall%2F×tamp={timestamp}' f'&versions={CDR_VERSION}ajfajfamsnfaflfasakljdlalkflak') data = { "return_url": "https%3A%2F%2Fapp.vocabgo.com%2Foverall%2F", "timestamp": timestamp, "versions": CDR_VERSION, "sign": sign } res = requests.post(url='https://gateway.vocabgo.com/Auth/Wechat/Config', headers=settings.header, json=data) _logger.i("WechatConfig:") _logger.i(res.content.decode("utf8")) res.close() time.sleep(1) # 信息显示 Tool.cls() loop = asyncio.get_event_loop() while True: if json['user_info'].get('class_name') is None: _logger.v(f"\n{json['user_info']['student_name']}(未加入班级)\n") else: _logger.v( f"\n{json['user_info']['student_name']}({json['user_info']['class_name']})\n" ) _logger.v("1.班级任务\n2.自选任务\n3.删除本地授权信息(可更换账号刷题)" "\n4.打开配置文件(关闭后将自动重载配置文件,记得保存)" "\n\n#.加群1085739587免费获取最新版,更少的BUG、更高的准确率\n\n0.退出\n") settings.save() choose = input("请输入序号:") if choose == "1": _logger.i("正在加载任务列表中,请稍等......") loop.run_until_complete(ClassTask().run()) Tool.cls() elif choose == "2": _logger.i("正在加载任务列表中,请稍等......") URL.load_myself_task_list() loop.run_until_complete( MyselfTask(json['user_info']['course_id']).run()) Tool.cls() elif choose == "3": settings.user_token = "" settings.save() Login() Tool.cls() elif choose == "4": os.system(f'notepad {CONFIG_DIR_PATH + "config.txt"}') settings.reload() Tool.cls() elif choose == "0": aiorequset.close_session() sys.exit(0) else: Tool.cls() _logger.i("输入格式有误!\n") res = requests.get( "https://gateway.vocabgo.com/Student/Main?timestamp=" f"{Tool.time()}&versions={CDR_VERSION}", headers=settings.header) json = res.json()["data"] res.close()
def _generate_qr_code(): user_agent = settings.user_agent user_token = settings.user_token now_time = Tool.time() # 获取13位时间戳 # 生成token pass_list = 'abcde0123456789' for _ in range(0, 32): index = random.randint(0, len(pass_list) - 1) user_token += pass_list[index] user_token = Tool.md5(f"{user_token}{Tool.time()}") # 生成token认证连接 sign = Tool.md5( f'auth_type=1&return_url=https://app.vocabgo.com/overall/#/student/home×tamp={now_time}' + f'&user_token={user_token}&versions={CDR_VERSION}ajfajfamsnfaflfasakljdlalkflak' ) data = { "return_url": "https://app.vocabgo.com/overall/#/student/home", "auth_type": 1, "user_token": user_token, "timestamp": now_time, "versions": CDR_VERSION, "sign": sign } headers = { 'Content-Type': 'application/json;charset=UTF-8', 'Host': 'app.vocabgo.com', 'Origin': 'https://app.vocabgo.com', 'Referer': 'https://app.vocabgo.com/', 'User-Agent': user_agent, # TODO 似乎是md5值,回头随机一个测试康康 # 'X-DevTools-Emulate-Network-Conditions-Client-Id': 'D9886F0A0D37C25B2E9998FEC289C919', 'X-DevTools-Emulate-Network-Conditions-Client-Id': Tool.md5(user_agent).upper(), 'X-Requested-With': 'XMLHttpRequest' } _logger.i( f'https://gateway.vocabgo.com/Auth/Thirdpart/Authorize?{data}') res = requests.post( url='https://gateway.vocabgo.com/Auth/Thirdpart/Authorize', headers=headers, json=data) json_str1 = res.json() res.close() login_url = json_str1['data']['redirect_url'] _logger.i("user_token:" + user_token) settings.user_token = user_token qr = qrcode.QRCode(version=2, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=3, border=1) # 设置二维码的大小 qr.add_data(login_url) qr.make(fit=True) img = qr.make_image() _logger.i("二维码已生成,将自动展示,请使用微信扫一扫进行词达人授权。成功后请关闭图片查看程序,若无法自动展示,用户可在" "“main目录\\config目录”下找到“授权二维码.jpg,自行打开照片进行扫码授权”") img.save(f"{CONFIG_DIR_PATH}授权二维码.jpg") img.show() # 显示图片
async def do_task(self, task, course_id, course): time_out = settings.timeout is_random_score = settings.is_random_score is_show = not settings.is_multiple_chapter if task['over_status'] == 2: task_id = task["task_id"] task_type = task["task_type"] release_id = task["release_id"] now_score = CDRTask.get_random_score(is_open=is_random_score) _logger.i("course_id:" + course_id, is_show=False) _logger.i("开始做【" + task["task_name"] + "】,目标分数:" + str(now_score), is_show=is_show) answer = Answer(course) if course else Answer(Course(course_id)) _logger.i("题库装载完毕!", is_show=is_show) count = 0 while True: count += 1 if count > 3: _logger.w("相同任务重复答题次数过多,疑似存在无法找到答案的题目,自动跳过本任务", is_show=is_show) break _logger.i("模拟加载流程", is_show=is_show) if task_type == 1: # 模拟加载流程 _logger.i("班级-学习任务", is_show=is_show) # 处理taskId为-1的情况 task_id = await ClassTask.get_task_id(task_id, release_id) await asyncio.sleep(1) data = { "task_id": task_id, "task_type": task_type, "release_id": release_id, "timestamp": Tool.time(), "versions": CDR_VERSION } res = await requests.get(url='https://gateway.vocabgo.com/Student/ClassTask/StartAnswer', headers=settings.header, params=data, timeout=time_out) json_data = await res.json() res.close() if json_data["code"] == 21006: await self.verify_human(task_id) data["timestamp"] = Tool.time() res = await requests.get(url='https://gateway.vocabgo.com/Student/ClassTask/StartAnswer', headers=settings.header, params=data, timeout=time_out) json_data = await res.json() res.close() if task_type == 1: # 判断是否需要选词 try: if json_data["code"] == 20001 and await ClassTask.choose_word(course_id, task_id, task_type): break except NoPermission as e: _logger.w(e) _logger.w("疑似未开通VIP课程,请自行购买VIP课程或反馈至学校购买后再进行答题操作") break # 开始任务包 timestamp = Tool.time() data = { "task_id": task_id, "task_type": task_type, "release_id": release_id, "timestamp": timestamp, "versions": CDR_VERSION } res = await requests.get(url='https://gateway.vocabgo.com/Student/ClassTask/StartAnswer', headers=settings.header, params=data, timeout=time_out) json_data = await res.json() res.close() if json_data["code"] == 21006: await self.verify_human(task_id) data["timestamp"] = Tool.time() res = await requests.get(url='https://gateway.vocabgo.com/Student/ClassTask/StartAnswer', headers=settings.header, params=data, timeout=time_out) json_data = await res.json() res.close() await asyncio.sleep(1) if json_data["code"] == 0 and json_data["msg"] is not None \ and json_data["msg"].find("返回首页") != -1: _logger.i("任务信息加载失败,返回上一级重选任务即可", is_show=is_show) input("按回车返回上一级") return # 判断是否跳过学习阶段 _logger.i(json_data, is_show=False) if json_data["data"]["topic_mode"] == 0: json_data = await ClassTask.skip_learn_task(json_data["data"]["topic_code"]) _logger.i("已跳过学习阶段", is_show=is_show) else: _logger.i("班级-测试任务", is_show=is_show) # 开始任务包 await asyncio.sleep(1) _logger.i("开始答题\n", is_show=is_show) if json_data["code"] == 0: _logger.i(json_data["msg"], is_show=is_show) return if settings.is_multiple_chapter: _logger.i(json_data, is_show=False) self.add_progress(str(release_id), task['task_name'], json_data['data']['topic_total']) self.update_progress(str(release_id), 0) # 提交做题 # code=20004时代表当前题目已做完,测试任务完成标志 # code=20001需要选词,学习任务完成标志 while json_data["code"] != 20004 and json_data["code"] != 20001 and \ json_data["data"]["topic_done_num"] <= json_data["data"]["topic_total"]: if settings.is_multiple_chapter: self.update_progress(str(release_id), json_data["data"]["topic_done_num"]) json_data = await self.do_question(answer, json_data, release_id, now_score, task_id) if is_show: _logger.i(f"【{task['task_name']}】已完成。分数:{await ClassTask.get_class_task_score(release_id)}") else: self.finish_progress(str(release_id), f"分数:{await ClassTask.get_class_task_score(release_id)}") if json_data["code"] == 20004: break if now_score <= await ClassTask.get_class_task_score(release_id): break else: _logger.i(f"该【{task['task_name']}】任务未开始")
async def run(self): task_type_list = ["未知", "学习", "测试"] over_status_list = ["未知", "未开始", "进行中", "已过期"] time_type_list = ["未知", "开始", "截止", "截止"] task_list = await ClassTask.get_task_list() # 任务选择 if len(task_list) == 0: _logger.i("全部任务已完成,无可做任务") input("按回车键返回上一级") return Tool.cls() while True: _logger.v("请输入序号去选择要做的任务:\n") for i, task in enumerate(task_list): time_stamp = task['start_time'] if task['over_status'] != 1: time_stamp += task['over_time'] time_stamp /= 1000 _logger.i(time_stamp, is_show=False) import time format_time = time.strftime("%m{m}%d{d} %H:%M:%S", time.localtime(time_stamp)).format(m="月", d="号") _logger.i(format_time, is_show=False) _logger.v(f"{i + 1:2d}. [{task_type_list[task['task_type']]}]" + f"[{over_status_list[task['over_status']]}] {task['task_name']:20s}" + f"({task['score']:2.1f}分) {format_time}{time_type_list[task['over_status']]}") _logger.v("\n#. 以空格分割可一次性选择多个任务") _logger.v(f"#. 你可以在“main{CONFIG_DIR_PATH[1:]}config.txt文件”中修改配置项以控分/修改做题时间间隔等") _logger.v("\n\n0. 选择全部任务\n\n请输入序号:", end="") choose = ' '.join(input("").split()).split(" ") _logger.v(choose, is_show=False) task_choose_list = [] tem_flag = True if CDRTask.check_input_data(choose[0], 0): task_choose_list = task_list else: for c in choose: if not CDRTask.check_input_data(c, len(task_list)): tem_flag = False Tool.cls() _logger.i("输入格式有误!\n") break task_choose_list.append(task_list[int(c) - 1]) if tem_flag: break # 课程单词预处理加载 for task in task_choose_list: course_id = task.get("course_id") or re.match(r'.*/(.*)\.jpg', task["course_img_url"]).group(1) self._courses_set.add(course_id) course_map = await self.course_pretreatment() Tool.cls() for task in task_choose_list: # 未过期任务 # over_status为任务标识,1:未开始 2:进行中 3:已过期 # task_id仅作为辅助标识,若任务是多单元混合,其为-1,若是单独,则其为对应课程号 # task_type为任务类型标识(未证实) 1:学习任务 2:测试任务 course_id = task.get("course_id") or re.match(r'.*/(.*)\.jpg', task["course_img_url"]).group(1) self._tasks.add_task([ self.do_task(task, course_id, course_map[course_id]) for _ in range(settings.multiple_task) ]) await self.start_task() # 防止线程数量不足而独立于主线程完成任务 # self._progress.clear() _logger.i("本次全部任务已完成!") input("按回车键返回上一级")
async def do_task(self, task: dict, course_id: str, course: Course): URL.load_task_detail() time_out = settings.timeout is_random_score = settings.is_random_score is_show = not settings.is_multiple_chapter if task["score"] != 100: task_id = task["task_id"] now_score = CDRTask.get_random_score(is_open=is_random_score) _logger.i("course_id:" + course_id, is_show=False) _logger.i("开始做【" + task["task_name"] + "】,目标分数:" + str(now_score), is_show=is_show) answer = Answer(course) if course else Answer(Course(course_id)) _logger.i("题库装载完毕!", is_show=is_show) count = 0 while True: count += 1 if count > 3: _logger.w("相同任务重复答题次数过多,疑似存在无法找到答案的题目,自动跳过本任务", is_show=is_show) break _logger.i("模拟加载流程", is_show=is_show) # 模拟加载流程 data = { "task_id": task_id, "course_id": task['course_id'], "list_id": task['list_id'], "timestamp": Tool.time(), "versions": CDR_VERSION, } res = await requests.get(url=f"https://gateway.vocabgo.com/Student/StudyTask/Info", params=data, headers=settings.header, timeout=time_out) json_data = await res.json() res.close() # 解决ZZ词达人无法根据原本任务ID获取信息,只能通过默认获取。本BUG(这不能算我的BUG啊)由群友239***963提供 if json_data["code"] == 0: data["task_id"] = -1 _logger.v(data) res = await requests.get(url=f"https://gateway.vocabgo.com/Student/StudyTask/Info", params=data, headers=settings.header, timeout=time_out) json_data = await res.json() task_id = json_data["data"]["task_id"] or -1 grade = json_data["data"]["grade"] await asyncio.sleep(1) data = { "task_id": task_id, "task_type": task['task_type'], "course_id": task['course_id'], "list_id": task['list_id'], "grade": grade, "timestamp": Tool.time(), "versions": CDR_VERSION } res = await requests.get(url="https://gateway.vocabgo.com/Student/StudyTask/StartAnswer", params=data, headers=settings.header, timeout=time_out) json_data = await res.json() res.close() if json_data["code"] == 21006: await self.verify_human(task_id) data["timestamp"] = Tool.time() res = await requests.get(url='https://gateway.vocabgo.com/Student/ClassTask/StartAnswer', headers=settings.header, params=data, timeout=time_out) json_data = await res.json() res.close() _logger.i("自选-学习任务", is_show=is_show) # 判断是否需要选词 if json_data["code"] == 20001 and await MyselfTask.choose_word(task, task_id, grade): break # 开始任务包 timestamp = Tool.time() data = { "task_id": task_id, "task_type": task["task_type"], "course_id": task["course_id"], "list_id": task["list_id"], "grade": grade, "timestamp": timestamp, "versions": CDR_VERSION } res = await requests.get(url='https://gateway.vocabgo.com/Student/StudyTask/StartAnswer', headers=settings.header, params=data, timeout=time_out) json_data = await res.json() res.close() await asyncio.sleep(1) if json_data["code"] == 0 and json_data["msg"] is not None \ and json_data["msg"].find("返回首页") != -1: _logger.i("任务信息加载失败,返回上一级重选任务即可", is_show=is_show) input("按回车返回上一级") return # 判断是否跳过学习阶段 _logger.i(json_data, is_show=False) if json_data["data"]["topic_mode"] == 0: json_data = await MyselfTask.skip_learn_task(json_data["data"]["topic_code"]) _logger.i("已跳过学习阶段", is_show=is_show) _logger.i("开始答题\n", is_show=is_show) if json_data["code"] == 0: _logger.i(json_data["msg"], is_show=is_show) return if settings.is_multiple_chapter: _logger.i(json_data, is_show=False) self.add_progress(task['list_id'], task['task_name'], json_data['data']['topic_total']) self.update_progress(task['list_id'], 0) # 提交做题 # code=20004时代表当前题目已做完,测试任务完成标志 # code=20001需要选词,学习任务完成标志 while json_data["code"] != 20004 and json_data["code"] != 20001 and \ json_data["data"]["topic_done_num"] <= json_data["data"]["topic_total"]: if settings.is_multiple_chapter: self.update_progress(task['list_id'], json_data["data"]["topic_done_num"]) json_data = await self.do_question(answer, json_data, course_id, task['list_id'], now_score, task_id) if is_show: _logger.i(f"【{task['task_name']}】已完成。" f"分数:{await MyselfTask.get_myself_task_score(course_id, task['list_id'])}") else: self.finish_progress(task['list_id'], f"分数:{await MyselfTask.get_myself_task_score(course_id, task['list_id'])}") if json_data["code"] == 20004: break if now_score <= await MyselfTask.get_myself_task_score(course_id, task['list_id']): break else: _logger.i(f"该【{task['task_name']}】任务已满分", is_show=is_show)
async def find_answer_and_finish(self, answer: Answer, data: dict, type_id: int, task_id: int) -> dict: is_show = not settings.is_multiple_chapter type_mode = ["StudyTask", "ClassTask"] content = data["stem"]["content"] remark = data["stem"]["remark"] topic_mode = data["topic_mode"] if topic_mode == 31: _logger.v(f"[mode:{topic_mode}]{str(content)}", end='', is_show=is_show) else: _logger.v(f"[mode:{topic_mode}]{content}({remark})", end='', is_show=is_show) topic_code = data["topic_code"] options = data["options"] time_spent = CDRTask.get_random_time(topic_mode, min_time=settings.min_random_time, max_time=settings.max_random_time) await asyncio.sleep(time_spent / 1000) # 根据获取到的答案与现行答案进行匹配 skip_times = 0 has_chance = True while has_chance: answer_id, is_skip = CDRTask.task_find_answer( answer, topic_mode, content, remark, options, skip_times) if is_skip: return await CDRTask.skip_answer(topic_code, topic_mode, type_mode[type_id]) # 答案验证 try: if topic_mode == 31: tem_list = answer_id for i in range(0, data["answer_num"]): answer_id = tem_list[i] topic_code, _ = await self.verify_answer( answer_id, topic_code, type_mode[type_id], task_id) if not settings.is_random_time: await asyncio.sleep(0.1) else: await asyncio.sleep( random.randint(3 * 1000, 5 * 1000) / 1000) has_chance = False else: topic_code, has_chance = await self.verify_answer( answer_id, topic_code, type_mode[type_id], task_id) except AnswerWrong as e: topic_code = e.topic_code if e.has_chance: skip_times += 1 _logger.w(e, is_show=False) _logger.w(f"第{skip_times}次查询答案出错,尝试跳过原答案进行搜索", is_show=False) continue _logger.v("") _logger.w("答案错误!") _logger.w(e) _logger.w("请携带error-last.txt寻找GM排除适配问题") _logger.w(f"你可以在“main{LOG_DIR_PATH[1:]}”下找到error-last.txt") _logger.create_error_txt() input("等待错误检查(按下回车键即可继续执行)") return await CDRTask.skip_answer(topic_code, topic_mode, type_mode[type_id]) else: has_chance = False _logger.v(" Done!", is_show=is_show) timestamp = Tool.time() sign = Tool.md5( f"time_spent={time_spent}×tamp={timestamp}&topic_code={topic_code}" + f"&versions={CDR_VERSION}ajfajfamsnfaflfasakljdlalkflak") data = { "topic_code": topic_code, "time_spent": time_spent, "timestamp": timestamp, "versions": CDR_VERSION, "sign": sign } res = await requests.post(url='https://gateway.vocabgo.com/Student/' + type_mode[type_id] + '/SubmitAnswerAndSave', json=data, headers=settings.header, timeout=settings.timeout) json_data = await res.json() res.close() if json_data["code"] == 21006: await self.verify_human(task_id) data["timestamp"] = Tool.time() res = await requests.post( url='https://gateway.vocabgo.com/Student/' + type_mode[type_id] + '/SubmitAnswerAndSave', json=data, headers=settings.header, timeout=settings.timeout) json_data = await res.json() res.close() # 请求模拟 # requests.post( # url='https://gateway.vocabgo.com/Student/Course/GetStudyWordInfo', # json=data, headers=settings.header, timeout=settings.timeout).close() return json_data
async def verify_human(self, task_id: int, check_type: str = "answer"): async with self._lock: data = { "check_type": check_type, "task_id": task_id, "versions": CDR_VERSION, } while True: data["timestamp"] = Tool.time() res = await requests.get( "https://gateway.vocabgo.com/Student/Captcha/Get", params=data, headers=settings.header, timeout=settings.timeout) json_data = await res.json() res.close() if json_data["code"] == 0 and json_data["msg"] == "无需验证": return elif json_data["code"] == 0: _logger.w(json_data["msg"]) _logger.w("词达人验证服务器暂时崩溃,请稍后再试") input() _logger.i("验证码即将展示,若看不清可输入-1重新生成") from cdr.utils import VerificationCode code = await VerificationCode.get_vc( json_data["data"]["original_image"], task_id) _logger.v(code) while code == "-1": res = await requests.get( "https://gateway.vocabgo.com/Student/Captcha/Get", params=data, headers=settings.header, timeout=settings.timeout) json_data = await res.json() res.close() if json_data["code"] == 0 and json_data["msg"] == "无需验证": return elif json_data["code"] == 0: _logger.v("") _logger.w(json_data["msg"]) _logger.w("词达人验证服务器暂时崩溃,请稍后再试") input("按回车重新尝试生成验证码") continue _logger.i("验证码即将展示,若看不清可输入-1重新生成") code = await VerificationCode.get_vc( json_data["data"]["original_image"], task_id) timestamp = Tool.time() sign = Tool.md5( f"captcha_code={code}&task_id={task_id}×tamp={timestamp}&versions={CDR_VERSION}" "ajfajfamsnfaflfasakljdlalkflak") data = { "captcha_code": code, "sign": sign, "task_id": task_id, "timestamp": timestamp, "versions": CDR_VERSION } res = await requests.post( "https://gateway.vocabgo.com/Student/Captcha/Check", json=data, headers=settings.header) flag = (await res.json())["code"] res.close() if flag != 1: _logger.i("验证码核验错误,将重新生成验证码")