1. 将 jwxt() 移动到 njupt_api 下,实现根据设置选择教务系统登录方式。
2. 将 api_router.py 和 mcp_router.py 中的对 ZhengFang() 的调用全部替换为对 jwxt() 的调用。
This commit is contained in:
2026-04-21 17:42:59 +08:00
parent b284c3c260
commit 16bd8e9f9a
9 changed files with 88 additions and 51 deletions

View File

@@ -0,0 +1,40 @@
from contextlib import asynccontextmanager
from typing import AsyncGenerator
from ..baselib import config
from .exc import LoginError
from .sso import SSO
from .zhengfang import ZhengFang
@asynccontextmanager
async def jwxt(username: str, password: str) -> AsyncGenerator[ZhengFang, None]:
"""
根据设置,选择 SSO 登录教务系统或直接登录教务系统。
Args:
username: 用户名str
password: 密码str
Yields:
zf: ZhengFang
Raises:
LoginError: 登录失败,包含下层返回的提示信息。
"""
try:
if config.get("schedule", "jwxt_login_method", "sso"):
sso = SSO()
await sso.start()
await sso.login(username, password)
zf = await ZhengFang.init_from_sso(sso)
else:
zf = ZhengFang()
await zf.start()
await zf.login(username, password)
except LoginError as e:
raise e
else:
yield zf
await zf.close()
return