增加步骤⑤: 检查并激活下一单元
This commit is contained in:
@@ -810,6 +810,44 @@ class EFCourseAutopilot:
|
||||
error=f"skip-exception: {e}",
|
||||
)
|
||||
|
||||
# --------------------------------------------------------
|
||||
# 步骤⑤: 激活下一单元
|
||||
# --------------------------------------------------------
|
||||
|
||||
def step_activate_next_unit(self) -> bool:
|
||||
"""检查当前单元是否已完成,若完成则激活下一单元"""
|
||||
if not self.ctx.unit_id:
|
||||
return False
|
||||
|
||||
url = f"{self.base_url}/wl/api/study-plan/study-plan"
|
||||
params = {
|
||||
"locale": self.locale,
|
||||
"clientTimezone": self.timezone,
|
||||
"courseId": self.ctx.course_id,
|
||||
"levelId": self.ctx.level_id,
|
||||
"unitId": self.ctx.unit_id,
|
||||
}
|
||||
headers = self._learn_headers()
|
||||
|
||||
resp = self.session.get(url, params=params, headers=headers, timeout=REQUEST_TIMEOUT)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
|
||||
is_completed = data.get("isUnitCompleted", False)
|
||||
next_unit_id = data.get("nextUnitId", "")
|
||||
|
||||
if is_completed and next_unit_id:
|
||||
self._log(f"当前单元已完成,激活下一单元 (nextUnitId={next_unit_id})")
|
||||
put_resp = self.session.put(
|
||||
url, params=params, json={"unitId": next_unit_id},
|
||||
headers=headers, timeout=REQUEST_TIMEOUT,
|
||||
)
|
||||
put_resp.raise_for_status()
|
||||
self._log(f"下一单元已激活 (status={put_resp.status_code})")
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
# --------------------------------------------------------
|
||||
# 主流程
|
||||
# --------------------------------------------------------
|
||||
@@ -912,6 +950,9 @@ class EFCourseAutopilot:
|
||||
elapsed = time.time() - start_time
|
||||
self._print_summary(total_tasks, elapsed)
|
||||
|
||||
# 步骤⑤: 检查并激活下一单元
|
||||
self.step_activate_next_unit()
|
||||
|
||||
return all(r.success for r in self.results)
|
||||
|
||||
except requests.exceptions.HTTPError as e:
|
||||
|
||||
Reference in New Issue
Block a user