feat: 维护中国代理池并支持账号自动均匀使用
This commit is contained in:
+23
-10
@@ -173,18 +173,31 @@ def _fetch_and_store(trigger: str) -> bool:
|
||||
return False
|
||||
password = decrypt_secret(account.password_cipher)
|
||||
credential = json.loads(decrypt_secret(account.credential_cipher))
|
||||
from euniv.proxy import url_of
|
||||
from euniv.proxy import bind_url, is_proxy_failure, uses_pool
|
||||
from euniv.proxy_pool import MAX_SWITCHES, mark_failed
|
||||
|
||||
proxy = url_of(account)
|
||||
client = EunivClient(employee_id, password, proxy=proxy)
|
||||
try:
|
||||
client.restore(credential)
|
||||
if not client.credential_alive():
|
||||
proxy = bind_url(account)
|
||||
courses = None
|
||||
last_exc: BaseException | None = None
|
||||
for _ in range(MAX_SWITCHES + 1):
|
||||
client = EunivClient(employee_id, password, proxy=proxy)
|
||||
try:
|
||||
client.restore(credential)
|
||||
if not client.credential_alive():
|
||||
return False
|
||||
courses = client.list_courses()
|
||||
last_exc = None
|
||||
break
|
||||
except Exception as exc:
|
||||
last_exc = exc
|
||||
if uses_pool(account) and proxy and is_proxy_failure(exc):
|
||||
mark_failed(employee_id, proxy, str(exc)[:200])
|
||||
proxy = bind_url(account)
|
||||
continue
|
||||
return False
|
||||
courses = client.list_courses()
|
||||
finally:
|
||||
client.close()
|
||||
if not courses:
|
||||
finally:
|
||||
client.close()
|
||||
if last_exc is not None or not courses:
|
||||
return False
|
||||
with SessionLocal() as db:
|
||||
db.execute(delete(Course))
|
||||
|
||||
Reference in New Issue
Block a user