Fix CHSI catalogue session verification and pagination
This commit is contained in:
+10
-2
@@ -15,8 +15,9 @@ class Shutdown(Exception):
|
||||
|
||||
|
||||
class JobManager:
|
||||
def __init__(self, database, settings, transport=None, runner=None):
|
||||
def __init__(self, database, settings, transport=None, runner=None, auth=None):
|
||||
self.db, self.settings, self.transport = database, settings, transport
|
||||
self.auth = auth
|
||||
self.runner = runner or self._collect
|
||||
self.controls = {}
|
||||
self.lock = threading.RLock()
|
||||
@@ -80,6 +81,8 @@ class JobManager:
|
||||
except Cancelled:
|
||||
self.db.job_update(jid, status="cancelled", message="已取消,已保存数据保留")
|
||||
except LoginRequired as exc:
|
||||
if self.auth:
|
||||
self.auth.invalidate(str(exc), state="captcha_required" if exc.reason == "captcha" else "login_required")
|
||||
self.db.job_update(jid, status="waiting_login", message=str(exc))
|
||||
self.db.log(jid, "warning", str(exc))
|
||||
except ProxyUnavailable as exc:
|
||||
@@ -186,8 +189,13 @@ class JobManager:
|
||||
self._scores(jid, params)
|
||||
|
||||
def _catalog(self, jid, params):
|
||||
client = CatalogClient(self.transport)
|
||||
client = CatalogClient(self.transport, auth=self.auth)
|
||||
client.verify_year(params["year"])
|
||||
if self.auth:
|
||||
status = self.auth.check()
|
||||
if not status["valid"]:
|
||||
raise LoginRequired(status["message"], reason="captcha" if status["state"] == "captcha_required" else "login")
|
||||
self.db.log(jid, "info", "研招目录会话已同步,第二页访问验证成功")
|
||||
for province in params["provinces"]:
|
||||
self.checkpoint(jid)
|
||||
self.db.log(jid, "info", "查询 " + PROVINCES[province] + " 院校")
|
||||
|
||||
Reference in New Issue
Block a user