Compare commits
5 Commits
be2a1fb1bb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c446bb6fd3 | |||
| 48e9d0d4b2 | |||
| 229369c308 | |||
| e0a01af7cd | |||
| 703e3956f4 |
+62
-5
@@ -162,7 +162,14 @@ def build_response_gapfill(task: TaskInfo) -> dict:
|
||||
"""gapfill: 填空题 — 优先使用expectedResponse中的正确答案"""
|
||||
expected = task.expected_response.get("contents", {}).get("gapfill", {})
|
||||
if expected:
|
||||
return {"gapfill": expected}
|
||||
result = {}
|
||||
for gid, gdata in expected.items():
|
||||
user_input = gdata.get("userInput", "")
|
||||
# 处理 "friendlier | more friendly" 多答案格式,取第一个
|
||||
if " | " in user_input:
|
||||
user_input = user_input.split(" | ")[0].strip()
|
||||
result[gid] = {"id": gid, "userInput": user_input}
|
||||
return {"gapfill": result}
|
||||
|
||||
# 回退:从task.detail获取gap列表, 填入空字符串
|
||||
gf = task.task_detail.get("gapfill", {})
|
||||
@@ -883,6 +890,60 @@ class EFCourseAutopilot:
|
||||
self._log(f"下一单元已激活 (status={put_resp.status_code})")
|
||||
return True
|
||||
|
||||
if is_completed and not next_unit_id:
|
||||
self._log("当前等级所有单元已完成,尝试切换至下一等级")
|
||||
try:
|
||||
levels_url = f"{self.base_url}/wl/api/change-level/levels"
|
||||
levels_resp = self.session.get(
|
||||
levels_url, params={"locale": self.locale},
|
||||
headers=headers, timeout=REQUEST_TIMEOUT,
|
||||
)
|
||||
levels_resp.raise_for_status()
|
||||
levels_data = levels_resp.json()
|
||||
|
||||
current_level_id = levels_data.get("currentLevelId")
|
||||
levels = levels_data.get("levels", [])
|
||||
if not current_level_id or not levels:
|
||||
self._log("无法获取等级信息,跳过等级切换")
|
||||
return False
|
||||
|
||||
# 找到 currentLevelId 之后的第一个未开始的等级
|
||||
found_current = False
|
||||
next_level = None
|
||||
for level in levels:
|
||||
lid = level.get("id") or level.get("levelId")
|
||||
if not found_current:
|
||||
if lid == current_level_id:
|
||||
found_current = True
|
||||
continue
|
||||
status = level.get("progress", {}).get("status", "")
|
||||
if status == "not_started":
|
||||
next_level = level
|
||||
break
|
||||
if status == "started":
|
||||
next_level = level
|
||||
break
|
||||
|
||||
if next_level:
|
||||
next_level_id = next_level.get("id") or next_level.get("levelId")
|
||||
self._log(f"切换至下一等级 (levelId={next_level_id})")
|
||||
study_plan_url = f"{self.base_url}/wl/api/study-plan/study-plan"
|
||||
put_resp = self.session.put(
|
||||
study_plan_url,
|
||||
params={"locale": self.locale},
|
||||
json={"courseId": self.ctx.course_id, "levelId": next_level_id},
|
||||
headers=headers, timeout=REQUEST_TIMEOUT,
|
||||
)
|
||||
put_resp.raise_for_status()
|
||||
self._log(f"等级切换成功 (status={put_resp.status_code})")
|
||||
return True
|
||||
else:
|
||||
self._log("未找到可切换的下一等级")
|
||||
except Exception as e:
|
||||
self._log(f"等级切换失败: {e}")
|
||||
|
||||
return False
|
||||
|
||||
return False
|
||||
|
||||
|
||||
@@ -929,10 +990,6 @@ class EFCourseAutopilot:
|
||||
lesson_key = f"{self.ctx.course_id}:{self.ctx.node_id}"
|
||||
if lesson_key in self._processed_lessons:
|
||||
self.repeat_detected = True
|
||||
self._log("\n⚠️ 检测到重复课程!该课程已处理过但未能晋级。")
|
||||
self._log(" 请手动完成此课程,处理方式二选一:")
|
||||
self._log(" ① 打开F12录制HAR,从课程列表到学习完成的全流程,将har文件发给开发者优化")
|
||||
self._log(" ② 直接手动学习完成,完成后本程序将继续处理后续课程")
|
||||
return False
|
||||
|
||||
# 步骤②: 注册课程会话
|
||||
|
||||
+45
-10
@@ -11,6 +11,7 @@ token 需从浏览器开发者工具中获取,详见 README.md。
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import random
|
||||
import sys
|
||||
import time
|
||||
|
||||
@@ -36,6 +37,19 @@ def read_token(token_file: str) -> str:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
QUOTES = [
|
||||
"我的答案是乱编的,但我的坚持是真的",
|
||||
"孩子不会了,所以孩子放弃了",
|
||||
"代码替我上课,良心替我请假",
|
||||
"EF 没教会我英语,但我教会了 EF 怎么跑路",
|
||||
"我提交的不是答案,是对教育系统的一封情书",
|
||||
"这门课过了,但我的英语水平还卡在加载中",
|
||||
"别人是来学习的,我是来给服务器刷数据的",
|
||||
"如果努力有用的话,我还要写脚本干嘛",
|
||||
"我和这门课,总得先疯一个",
|
||||
]
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="EF Course Autopilot — 交互式循环运行",
|
||||
@@ -99,22 +113,43 @@ token.txt 说明:
|
||||
verify_ssl=args.verify_ssl,
|
||||
)
|
||||
|
||||
try:
|
||||
success = autopilot.run()
|
||||
if autopilot.repeat_detected:
|
||||
print("\n⚠️ 检测到重复课程,自动循环终止。")
|
||||
print(" 请手动完成此课程,处理方式二选一:")
|
||||
print(" ① 打开F12录制HAR,从课程列表到学习完成的全流程,将har文件发给开发者优化")
|
||||
print(" ② 直接手动学习完成,完成后重新运行本程序继续后续课程")
|
||||
max_retries = 3
|
||||
for attempt in range(max_retries + 1):
|
||||
try:
|
||||
success = autopilot.run()
|
||||
except Exception as e:
|
||||
print(f"\n❌ 课程执行异常: {e}")
|
||||
if attempt < max_retries:
|
||||
print(f" 第 {attempt + 1}/{max_retries} 次重试...\n")
|
||||
autopilot = EFCourseAutopilot(
|
||||
token=token,
|
||||
skip_on_fail=True,
|
||||
verify_ssl=args.verify_ssl,
|
||||
)
|
||||
continue
|
||||
total_fail += 1
|
||||
break
|
||||
|
||||
if autopilot.repeat_detected:
|
||||
if attempt < max_retries:
|
||||
print(f"\n⚠️ 检测到重复,第 {attempt + 1}/{max_retries} 次重试...\n")
|
||||
autopilot = EFCourseAutopilot(
|
||||
token=token,
|
||||
skip_on_fail=True,
|
||||
verify_ssl=args.verify_ssl,
|
||||
)
|
||||
continue
|
||||
print("\n⚠️ 检测到重复课程,自动循环终止。")
|
||||
print(f" 「{random.choice(QUOTES)}」 —— 凯特莎")
|
||||
print(" 请手动完成此课程,完成后重新运行本程序继续后续课程。")
|
||||
total_fail += 1
|
||||
break
|
||||
|
||||
if success:
|
||||
total_success += 1
|
||||
else:
|
||||
total_fail += 1
|
||||
except Exception as e:
|
||||
print(f"\n❌ 课程执行异常: {e}")
|
||||
total_fail += 1
|
||||
break
|
||||
|
||||
elapsed = time.time() - start_time
|
||||
print(f"\n{'#' * 60}")
|
||||
|
||||
Reference in New Issue
Block a user