feat: 保持浏览器登录,并显示我的学时里的本月学时

This commit is contained in:
2026-10-27 04:52:39 +08:00
parent afda5a883f
commit 7bbb80ee9c
10 changed files with 318 additions and 35 deletions
+34 -1
View File
@@ -5,6 +5,7 @@ from __future__ import annotations
import base64
import io
import random
import re
import time
import uuid
from urllib.parse import quote
@@ -134,7 +135,7 @@ class EunivClient:
block = payload.get("code") or {}
return block.get("code") or "", block.get("msg") or "", payload.get("bo")
def login(self) -> dict:
def login(self, manual: bool = False) -> dict:
self.client.get(EUNIV + "/")
self.client.post(
f"{PORTAL}/zte-bmt-ucs-portalbff/oauth/validate",
@@ -168,6 +169,9 @@ class EunivClient:
raise RuntimeError(f"安全码检查失败:{check_message}")
self._cipher = encrypt_password(public_key, self.password)
if manual:
self._load_jigsaw()
raise ManualJigsaw(self.current_puzzle())
for _ in range(3):
big, small, top = self._load_jigsaw()
try:
@@ -441,8 +445,37 @@ class EunivClient:
"today_score": today.get("studyScore"),
"pending_exam_count": pending_count,
"pending_exams": self._pending_exams(pending_count),
"month_hours": self._month_study_hours(),
}
def _month_study_hours(self) -> str:
text = self._study_period_page()
match = re.search(r'id="spMonthlyPeriod" title="(\d+)分钟"', text)
return match.group(1) if match else ""
def _study_period_page(self) -> str:
response = self.client.get(
f"{EUNIV}/study/myperiod.htm",
headers={"User-Agent": USER_AGENT, "Referer": EUNIV + "/sty/index.htm"},
)
if "spMonthlyPeriod" in response.text:
return response.text
if self._profile.get("token"):
self.authorize(self._profile)
response = self.client.get(
f"{EUNIV}/study/myperiod.htm",
headers={"User-Agent": USER_AGENT, "Referer": EUNIV + "/sty/index.htm"},
)
return response.text
def credential_alive(self) -> bool:
try:
response = self._request("POST", f"{YXT_API}/v1/customdiy/user/getuserinfobyid", content=b"")
except SessionExpired:
return False
payload = response.json()
return isinstance(payload, dict) and bool(payload.get("cnName"))
def _pending_exams(self, count: int) -> list[dict]:
if count <= 0:
return []