fix: 切换学时依据后立刻刷新,历史页不再拉整页首页

This commit is contained in:
2026-11-16 15:25:16 +08:00
parent 05f2396e35
commit 33640f7da8
4 changed files with 62 additions and 6 deletions
+27 -2
View File
@@ -608,10 +608,18 @@ def _exam_result(block: str, status: str) -> str:
return ""
def _exam_detail_path(value: str) -> bool:
def exam_path_ok(value: str) -> bool:
return bool(re.fullmatch(r"/exam/exampreview\.htm\?[A-Za-z0-9_=&%.\-]+", value)) and "xamArrangeID=" in value
def training_path_ok(value: str) -> bool:
return bool(re.fullmatch(r"/plan/[0-9a-fA-F]{32}\.html", value))
def _exam_detail_path(value: str) -> bool:
return exam_path_ok(value)
def _field(page: str, element_id: str) -> str:
match = re.search(rf'id="{re.escape(element_id)}"[^>]*>([\s\S]*?)</span>', page)
return _plain(match.group(1)) if match else ""
@@ -1155,6 +1163,23 @@ class EunivClient:
def home_trainings(self) -> list[dict]:
return _by_closeness(self.online_trainings(), "sort_days")
def hour_fields(self) -> dict:
"""只取四个学时数字,不读个人资料。"""
periods = self._period_minutes()
score_resp = self._request("POST", f"{YXT_API}/v1/customapiforweb/getscoreorpointorhour", json={})
score_payload = score_resp.json()
score = score_payload.get("data") or {}
if score_payload.get("code") not in (None, "0", 0):
raise RuntimeError(score_payload.get("message") or "学时学分查询失败")
today_resp = self._request("GET", f"{STUDY_API}/v1/studyapi/studyhour/todayscorehours")
today = today_resp.json()
return {
"year_hours": periods["year"],
"month_hours": periods["month"],
"today_hours": today.get("studyHours"),
"total_hours": score.get("actualStudyHour") or "",
}
def month_hours(self) -> str:
return self._period_minutes().get("month", "")
@@ -1331,7 +1356,7 @@ class EunivClient:
return parse_exam_detail(self._site_page(path))
def training_detail(self, path: str) -> dict:
if not re.fullmatch(r"/plan/[0-9a-fA-F]{32}\.html", path):
if not training_path_ok(path):
raise RuntimeError("培训明细无法打开")
return parse_training_detail(self._site_page(path))