fix: 补上清单里还没对上的登录拒绝、会话回退和代理清理
This commit is contained in:
+16
-8
@@ -439,7 +439,7 @@ def history_hour_totals(items: list[dict], now: datetime | None = None) -> dict[
|
||||
}
|
||||
|
||||
|
||||
def accumulate_month_minutes(fetch_page, year: int, month: int, page_size: int = HISTORY_PAGE_SIZE) -> int:
|
||||
def accumulate_month_minutes(fetch_page, year: int, month: int, page_size: int = HISTORY_PAGE_SIZE) -> tuple[int, bool]:
|
||||
"""倒序分页累加本月分钟,遇到上个月即停。重复页直接返回,不再累加。"""
|
||||
offset = 0
|
||||
total = 0
|
||||
@@ -449,9 +449,9 @@ def accumulate_month_minutes(fetch_page, year: int, month: int, page_size: int =
|
||||
if rows is None:
|
||||
if offset == 0:
|
||||
raise RuntimeError("学时历史没有获取到")
|
||||
return total
|
||||
return total, False
|
||||
if not rows:
|
||||
return total
|
||||
return total, False
|
||||
mark = (
|
||||
len(rows),
|
||||
rows[0].get("studied_at"),
|
||||
@@ -460,14 +460,14 @@ def accumulate_month_minutes(fetch_page, year: int, month: int, page_size: int =
|
||||
rows[-1].get("title"),
|
||||
)
|
||||
if mark in seen:
|
||||
return total
|
||||
return total, False
|
||||
seen.add(mark)
|
||||
add, done = fold_month_minutes(rows, year, month)
|
||||
total += add
|
||||
if done or len(rows) != page_size:
|
||||
return total
|
||||
return total, False
|
||||
offset += page_size
|
||||
return total
|
||||
return total, True
|
||||
|
||||
|
||||
def parse_training_cards(page: str, status: str) -> list[dict]:
|
||||
@@ -744,6 +744,10 @@ class JigsawRejected(RuntimeError):
|
||||
"""这次拼图位置不对,可以换一张再试。"""
|
||||
|
||||
|
||||
class LoginRejected(RuntimeError):
|
||||
"""平台明确拒绝了账号或密码,不能再自动重试。"""
|
||||
|
||||
|
||||
class ManualJigsaw(Exception):
|
||||
"""自动拼图已用完,把新拼图交给人来拖。"""
|
||||
|
||||
@@ -967,7 +971,9 @@ class EunivClient:
|
||||
return profile
|
||||
if any(word in message for word in ("验证码", "拼图", "滑块")):
|
||||
raise JigsawRejected(message or "拼图未通过")
|
||||
raise RuntimeError(f"登录失败:{message}")
|
||||
if any(word in message for word in ("密码", "账号", "用户名", "工号")):
|
||||
raise LoginRejected("账号或密码错误")
|
||||
raise RuntimeError("登录没有完成")
|
||||
|
||||
def authorize(self, profile: dict) -> None:
|
||||
account_id = str(profile.get("accountId") or profile.get("userName") or "")
|
||||
@@ -1209,7 +1215,9 @@ class EunivClient:
|
||||
return self._study_history_search(pageable=True, offset=offset, limit=limit)
|
||||
|
||||
try:
|
||||
return accumulate_month_minutes(fetch_page, year, month)
|
||||
total, limited = accumulate_month_minutes(fetch_page, year, month)
|
||||
self.history_limited = limited
|
||||
return total
|
||||
except SessionExpired:
|
||||
raise
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user