papersearch 0.7.3 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +8 -37
- package/README.fr.md +265 -0
- package/README.ja.md +265 -0
- package/README.ko.md +265 -0
- package/README.md +149 -148
- package/README.zh-Hant.md +265 -0
- package/README.zh.md +265 -0
- package/dist/capabilities/download/batch/batch.d.ts +20 -1
- package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batch.js +1057 -208
- package/dist/capabilities/download/batch/batch.js.map +1 -1
- package/dist/capabilities/download/batch/batchFolder.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batchFolder.js +3 -2
- package/dist/capabilities/download/batch/batchFolder.js.map +1 -1
- package/dist/capabilities/download/batch/networkLoss.d.ts +11 -2
- package/dist/capabilities/download/batch/networkLoss.d.ts.map +1 -1
- package/dist/capabilities/download/batch/networkLoss.js +24 -3
- package/dist/capabilities/download/batch/networkLoss.js.map +1 -1
- package/dist/capabilities/download/batch/resume.d.ts +7 -0
- package/dist/capabilities/download/batch/resume.d.ts.map +1 -1
- package/dist/capabilities/download/batch/resume.js +50 -9
- package/dist/capabilities/download/batch/resume.js.map +1 -1
- package/dist/capabilities/download/batch/windowPlan.d.ts +96 -0
- package/dist/capabilities/download/batch/windowPlan.d.ts.map +1 -0
- package/dist/capabilities/download/batch/windowPlan.js +196 -0
- package/dist/capabilities/download/batch/windowPlan.js.map +1 -0
- package/dist/capabilities/download/content/markdown/pro.d.ts +6 -0
- package/dist/capabilities/download/content/markdown/pro.d.ts.map +1 -1
- package/dist/capabilities/download/content/markdown/pro.js.map +1 -1
- package/dist/capabilities/download/content/markdown/shortfall.d.ts +8 -5
- package/dist/capabilities/download/content/markdown/shortfall.d.ts.map +1 -1
- package/dist/capabilities/download/content/markdown/shortfall.js +22 -10
- package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -1
- package/dist/capabilities/download/content/markdown/step.d.ts +9 -0
- package/dist/capabilities/download/content/markdown/step.d.ts.map +1 -1
- package/dist/capabilities/download/content/markdown/step.js +46 -3
- package/dist/capabilities/download/content/markdown/step.js.map +1 -1
- package/dist/capabilities/download/content/markdown/types.d.ts +10 -1
- package/dist/capabilities/download/content/markdown/types.d.ts.map +1 -1
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.d.ts.map +1 -1
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.js +3 -1
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.js.map +1 -1
- package/dist/capabilities/download/handler.d.ts.map +1 -1
- package/dist/capabilities/download/handler.js +13 -5
- package/dist/capabilities/download/handler.js.map +1 -1
- package/dist/capabilities/download/outputLayout.d.ts.map +1 -1
- package/dist/capabilities/download/outputLayout.js +3 -1
- package/dist/capabilities/download/outputLayout.js.map +1 -1
- package/dist/capabilities/download/tools.js +2 -2
- package/dist/capabilities/download/tools.js.map +1 -1
- package/dist/capabilities/download/types.d.ts +9 -1
- package/dist/capabilities/download/types.d.ts.map +1 -1
- package/dist/cli.js +3 -1
- package/dist/cli.js.map +1 -1
- package/dist/infrastructure/http/hostGate.d.ts +24 -0
- package/dist/infrastructure/http/hostGate.d.ts.map +1 -0
- package/dist/infrastructure/http/hostGate.js +72 -0
- package/dist/infrastructure/http/hostGate.js.map +1 -0
- package/dist/infrastructure/pdf/PdfDownload.d.ts +1 -0
- package/dist/infrastructure/pdf/PdfDownload.d.ts.map +1 -1
- package/dist/infrastructure/pdf/PdfDownload.js +6 -1
- package/dist/infrastructure/pdf/PdfDownload.js.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.d.ts +14 -0
- package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.js +30 -4
- package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts +2 -1
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +27 -4
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.d.ts +11 -0
- package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.js +48 -5
- package/dist/infrastructure/school/SchoolAttempt.js.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.d.ts +13 -2
- package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.js +138 -15
- package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -1
- package/dist/infrastructure/school/SchoolProgress.d.ts +2 -0
- package/dist/infrastructure/school/SchoolProgress.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolProgress.js +2 -0
- package/dist/infrastructure/school/SchoolProgress.js.map +1 -1
- package/dist/infrastructure/school/SchoolReadiness.d.ts +9 -0
- package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolReadiness.js +10 -0
- package/dist/infrastructure/school/SchoolReadiness.js.map +1 -1
- package/dist/infrastructure/school/SchoolResultNormalizer.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolResultNormalizer.js +4 -0
- package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -1
- package/dist/infrastructure/school/index.d.ts +2 -2
- package/dist/infrastructure/school/index.d.ts.map +1 -1
- package/dist/infrastructure/school/index.js +1 -1
- package/dist/infrastructure/school/index.js.map +1 -1
- package/dist/infrastructure/school/types.d.ts +73 -1
- package/dist/infrastructure/school/types.d.ts.map +1 -1
- package/dist/infrastructure/school/types.js.map +1 -1
- package/dist/infrastructure/security/SecurityUtils.d.ts.map +1 -1
- package/dist/infrastructure/security/SecurityUtils.js +6 -2
- package/dist/infrastructure/security/SecurityUtils.js.map +1 -1
- package/dist/management/failures/index.d.ts +23 -0
- package/dist/management/failures/index.d.ts.map +1 -1
- package/dist/management/failures/index.js +68 -20
- package/dist/management/failures/index.js.map +1 -1
- package/dist/management/school/autoUpdate.d.ts.map +1 -1
- package/dist/management/school/autoUpdate.js +9 -1
- package/dist/management/school/autoUpdate.js.map +1 -1
- package/dist/management/school/cliProgress.d.ts.map +1 -1
- package/dist/management/school/cliProgress.js +3 -1
- package/dist/management/school/cliProgress.js.map +1 -1
- package/package.json +8 -3
- package/school/NOTICE +3 -2
- package/school/paper_search_school/adapters/__init__.py +2 -0
- package/school/paper_search_school/adapters/aps/__init__.py +3 -6
- package/school/paper_search_school/adapters/base.py +19 -2
- package/school/paper_search_school/adapters/copernicus/__init__.py +2 -7
- package/school/paper_search_school/adapters/elsevier/__init__.py +50 -1
- package/school/paper_search_school/adapters/frontiers/__init__.py +41 -2
- package/school/paper_search_school/adapters/ieee/__init__.py +6 -4
- package/school/paper_search_school/adapters/iop/__init__.py +8 -0
- package/school/paper_search_school/adapters/jama/__init__.py +8 -0
- package/school/paper_search_school/adapters/lww/__init__.py +14 -6
- package/school/paper_search_school/adapters/mdpi/__init__.py +12 -7
- package/school/paper_search_school/adapters/neurology/__init__.py +5 -2
- package/school/paper_search_school/adapters/optica/__init__.py +52 -13
- package/school/paper_search_school/adapters/oup/__init__.py +7 -4
- package/school/paper_search_school/adapters/platforms/__init__.py +4 -1
- package/school/paper_search_school/adapters/platforms/atypon/__init__.py +12 -3
- package/school/paper_search_school/adapters/platforms/figshare/__init__.py +23 -4
- package/school/paper_search_school/adapters/platforms/jstage/__init__.py +64 -0
- package/school/paper_search_school/adapters/taylor_francis/__init__.py +0 -3
- package/school/paper_search_school/adapters/thieme/__init__.py +2 -9
- package/school/paper_search_school/api_keys.py +63 -13
- package/school/paper_search_school/assets/api_keys.json +14 -0
- package/school/paper_search_school/assets/capsule.html +526 -147
- package/school/paper_search_school/assets/capsule_en.json +140 -49
- package/school/paper_search_school/assets/capsule_fr.json +141 -50
- package/school/paper_search_school/assets/capsule_ja.json +140 -49
- package/school/paper_search_school/assets/capsule_ko.json +140 -49
- package/school/paper_search_school/assets/capsule_zh-Hant.json +134 -48
- package/school/paper_search_school/browser/backend.py +125 -4
- package/school/paper_search_school/browser/batch_session.py +189 -8
- package/school/paper_search_school/browser/challenge/__init__.py +12 -9
- package/school/paper_search_school/browser/challenge/continuation.py +83 -0
- package/school/paper_search_school/browser/challenge/handlers/__init__.py +1 -0
- package/school/paper_search_school/browser/challenge/handlers/aws_waf.py +260 -0
- package/school/paper_search_school/browser/challenge/handlers/recaptcha_hcaptcha.py +167 -0
- package/school/paper_search_school/browser/challenge/handlers/text_captcha.py +128 -0
- package/school/paper_search_school/browser/challenge/handlers/turnstile.py +174 -0
- package/school/paper_search_school/browser/challenge/kinds.py +203 -0
- package/school/paper_search_school/browser/challenge/local/__init__.py +1 -0
- package/school/paper_search_school/browser/challenge/{interaction.py → local/interaction.py} +94 -13
- package/school/paper_search_school/browser/challenge/{pointer.py → local/pointer.py} +2 -2
- package/school/paper_search_school/browser/challenge/local/prompt.py +283 -0
- package/school/paper_search_school/browser/challenge/local/submission.py +33 -0
- package/school/paper_search_school/browser/challenge/pro.py +24 -0
- package/school/paper_search_school/browser/challenge/services/__init__.py +1 -0
- package/school/paper_search_school/browser/challenge/services/solver.py +292 -0
- package/school/paper_search_school/browser/engine.py +4 -1
- package/school/paper_search_school/browser/user_turn.py +126 -0
- package/school/paper_search_school/browser/watchdog.py +213 -60
- package/school/paper_search_school/cli_config.py +10 -5
- package/school/paper_search_school/config.py +16 -10
- package/school/paper_search_school/download_diagnostics.py +7 -2
- package/school/paper_search_school/engine/access_rules.py +12 -3
- package/school/paper_search_school/engine/batch.py +52 -18
- package/school/paper_search_school/engine/batch_access.py +62 -16
- package/school/paper_search_school/engine/batch_capture.py +260 -31
- package/school/paper_search_school/engine/batch_common.py +3 -0
- package/school/paper_search_school/engine/batch_diagnostics.py +25 -5
- package/school/paper_search_school/engine/batch_institution.py +52 -3
- package/school/paper_search_school/engine/batch_login.py +398 -36
- package/school/paper_search_school/engine/batch_pdf_urls.py +38 -7
- package/school/paper_search_school/engine/batch_user.py +48 -3
- package/school/paper_search_school/engine/batch_waits.py +221 -14
- package/school/paper_search_school/engine/bridge.py +29 -6
- package/school/paper_search_school/engine/fulltext_page.py +55 -8
- package/school/paper_search_school/engine/router.py +16 -1
- package/school/paper_search_school/engine/supplements.py +7 -1
- package/school/paper_search_school/entitlements.py +29 -1
- package/school/paper_search_school/pdf_utils.py +25 -16
- package/school/paper_search_school/progress_capsule.py +69 -11
- package/school/paper_search_school/progress_reporter.py +243 -11
- package/school/paper_search_school/progress_view.py +205 -91
- package/school/paper_search_school/publishers/builtin/iop.json +2 -1
- package/school/paper_search_school/publishers/builtin/neurology.json +4 -2
- package/school/paper_search_school/publishers/site.py +12 -4
- package/school/paper_search_school/rate_limit.py +24 -1
- package/school/paper_search_school/school_login.py +170 -8
- package/school/paper_search_school/school_test.py +1 -1
- package/school/paper_search_school/server.py +179 -23
- package/school/paper_search_school/user_settings.py +46 -4
- package/school/pyproject.toml +1 -0
- package/skills/paper-search/SKILL.md +107 -107
- package/skills/paper-search/references/browser-download.md +102 -99
- package/skills/paper-search/references/capability-routing.md +89 -89
- package/skills/paper-search/references/cli-contract.md +78 -78
- package/skills/paper-search/references/federation-support.md +172 -172
- package/skills/paper-search/references/management-layer.md +78 -78
- package/skills/paper-search/references/publisher-support.md +38 -38
- package/skills/paper-search/references/school-setup.md +56 -55
- package/skills/paper-search/references/setup.md +20 -20
- package/skills/paper-search/references/troubleshooting.md +12 -12
- package/README.en.md +0 -264
- package/school/paper_search_school/browser/challenge/prompt.py +0 -154
|
@@ -64,6 +64,7 @@ MAX_LISTED_PAPERS = 200
|
|
|
64
64
|
CLASS_ORDER = ("no_access", "user_side", "external", "unsupported", "unexplained")
|
|
65
65
|
DEFAULT_LINGER_SECONDS = 8.0
|
|
66
66
|
NOTICE_SECONDS = 10.0 # how long the download's answer to a click stays on screen
|
|
67
|
+
SWITCH_SECONDS = 5.0 # how long the card names the school the papers without access go on with
|
|
67
68
|
|
|
68
69
|
|
|
69
70
|
class AutoClose:
|
|
@@ -258,24 +259,33 @@ def summary_view(results: Any) -> dict[str, Any] | None:
|
|
|
258
259
|
|
|
259
260
|
|
|
260
261
|
OPEN_DOWNLOAD = "开放下载"
|
|
262
|
+
# Behind 重试 (user, 2026-11-24): the papers held for a later try, by why, as the card says them.
|
|
263
|
+
RETRY_GROUPS = (("no_access", "换学校再试 · 没权限"), ("unexplained", "最后再试一次 · 原因不明"), ("blocked", "被网站拦截"),
|
|
264
|
+
("login", "登录后继续 · 学校登录中途失效"))
|
|
261
265
|
# Behind 剩余: the paper being downloaded, then the waiting ones by lane.
|
|
262
266
|
LEFT_GROUPS = (("now", "正在下载"), ("school", "排队等机构下载"), ("open", "开放下载还没查"))
|
|
263
267
|
|
|
264
268
|
|
|
265
|
-
def paper_lists(listed: Any, state: dict[str, Any] | None) -> dict[str, Any]:
|
|
266
|
-
"""The lists behind the card's 成功,
|
|
269
|
+
def paper_lists(listed: Any, state: dict[str, Any] | None, holds: bool = True) -> dict[str, Any]:
|
|
270
|
+
"""The lists behind the card's 成功, 失败, 重试 and 剩余, from the batch's papers (``sync_papers``).
|
|
267
271
|
|
|
268
272
|
``ok``: by the way each came (开放下载, its sources in brackets; 机构下载), a paper
|
|
269
273
|
opening its PDF by ``index``; ``failed``: by reason as on the finished card, a paper
|
|
270
274
|
opening its article page, then the saved papers missing supplementary files, by reason
|
|
271
275
|
(``supplement`` groups; ``count`` the failed papers only, ``supplement_count`` these); ``left``: the paper being downloaded, those waiting for the
|
|
272
276
|
institutional download and those open access has not checked yet. Each list has its
|
|
273
|
-
``count`` and groups, the first one open. Empty for another batch's papers.
|
|
277
|
+
``count`` and groups, the first one open. Empty for another batch's papers. ``holds`` false (neither
|
|
278
|
+
失败后自动重试 nor 没权限时换下一所学校 on, the card without 重试): no 重试 list, each paper where its state puts it."""
|
|
274
279
|
if not isinstance(listed, dict) or not state or listed.get("batch_id") != state.get("batch_id"):
|
|
275
280
|
return {}
|
|
276
281
|
papers = sorted((p for p in (listed.get("papers") or {}).values() if isinstance(p, dict)),
|
|
277
282
|
key=lambda p: _count(p.get("index")))
|
|
278
283
|
current = str(state.get("current") or "").lower() if state.get("status") == "running" else ""
|
|
284
|
+
# The papers the caller holds for a later try, by DOI (its ``later``): behind 重试, not 失败 nor 剩余 (user, 2026-11-24).
|
|
285
|
+
later = (state.get("later") if holds and state.get("status") == "running" and isinstance(state.get("later"), dict)
|
|
286
|
+
else {})
|
|
287
|
+
held = {doi.lower(): kind for kind, dois in (later.get("papers") or {}).items() for doi in dois}
|
|
288
|
+
held_paper = lambda paper: str(paper.get("doi") or "").lower() in held # noqa: E731
|
|
279
289
|
|
|
280
290
|
def row(paper: dict[str, Any], *where: Any) -> dict[str, Any]:
|
|
281
291
|
doi = str(paper.get("doi") or "").strip()
|
|
@@ -317,13 +327,14 @@ def paper_lists(listed: Any, state: dict[str, Any] | None) -> dict[str, Any]:
|
|
|
317
327
|
|
|
318
328
|
# A batch of the Markdown alone fails a paper for its Markdown: a site not yet supported's
|
|
319
329
|
# note stands in for the journal, as on the finished card (user, 2026-11-16).
|
|
320
|
-
|
|
330
|
+
asked = state.get("batch_content") or state.get("content") # the batch's, not the running article's
|
|
331
|
+
markdown_alone = asked == "markdown"
|
|
321
332
|
|
|
322
333
|
def site_note(paper: dict[str, Any]) -> dict[str, Any]:
|
|
323
334
|
note = str(paper.get("markdown_note") or "")
|
|
324
335
|
return {"note": note, "journal": "" if note else paper.get("journal")}
|
|
325
336
|
|
|
326
|
-
failed_papers = [p for p in papers if p.get("state") == "failed"]
|
|
337
|
+
failed_papers = [p for p in papers if p.get("state") == "failed" and not held_paper(p)]
|
|
327
338
|
failed = _reason_groups([{**p, **(site_note(p) if markdown_alone else {"note": ""})} for p in failed_papers], 0)
|
|
328
339
|
for item in failed:
|
|
329
340
|
item.update(label=item["reason"])
|
|
@@ -354,7 +365,7 @@ def paper_lists(listed: Any, state: dict[str, Any] | None) -> dict[str, Any]:
|
|
|
354
365
|
|
|
355
366
|
waiting: dict[str, list[dict[str, Any]]] = {key: [] for key, _ in LEFT_GROUPS}
|
|
356
367
|
for paper in papers:
|
|
357
|
-
if paper.get("state") not in ("open", "school"):
|
|
368
|
+
if paper.get("state") not in ("open", "school") or held_paper(paper):
|
|
358
369
|
continue
|
|
359
370
|
now = bool(current) and str(paper.get("doi") or "").lower() == current
|
|
360
371
|
way = "机构下载" if paper["state"] == "school" else OPEN_DOWNLOAD
|
|
@@ -375,41 +386,15 @@ def paper_lists(listed: Any, state: dict[str, Any] | None) -> dict[str, Any]:
|
|
|
375
386
|
missing = first_open(failed + short + markdown + doubt)
|
|
376
387
|
missing.update(count=sum(item["count"] for item in failed), supplement_count=sum(item["count"] for item in short),
|
|
377
388
|
markdown_count=sum(item["count"] for item in markdown), doubt_count=sum(item["count"] for item in doubt),
|
|
378
|
-
failed_title=failed_title(
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
whose rules converted their pages or came closest, ``rules`` (most papers first; none
|
|
388
|
-
when no rules read a page): the card says which were borrowed (user, 2026-11-17)."""
|
|
389
|
-
if not isinstance(listed, dict) or not state or listed.get("batch_id") != state.get("batch_id"):
|
|
390
|
-
return None
|
|
391
|
-
counts: dict[str, int] = {}
|
|
392
|
-
rules: dict[str, int] = {}
|
|
393
|
-
saved = unsaved = skipped = 0
|
|
394
|
-
for paper in (listed.get("papers") or {}).values():
|
|
395
|
-
if not isinstance(paper, dict) or not paper.get("markdown_host"):
|
|
396
|
-
continue
|
|
397
|
-
counts[str(paper["markdown_host"])] = counts.get(str(paper["markdown_host"]), 0) + 1
|
|
398
|
-
if paper.get("markdown_rules"):
|
|
399
|
-
rules[str(paper["markdown_rules"])] = rules.get(str(paper["markdown_rules"]), 0) + 1
|
|
400
|
-
if paper.get("markdown_saved"):
|
|
401
|
-
saved += 1
|
|
402
|
-
elif paper.get("markdown_skipped"):
|
|
403
|
-
skipped += 1
|
|
404
|
-
else:
|
|
405
|
-
unsaved += 1
|
|
406
|
-
if not counts:
|
|
407
|
-
return None
|
|
408
|
-
def most_first(tally: dict[str, int]) -> list[str]:
|
|
409
|
-
return [name for name, _ in sorted(tally.items(), key=lambda kv: (-kv[1], kv[0]))]
|
|
410
|
-
|
|
411
|
-
return {"hosts": most_first(counts), "saved": saved, "unsaved": unsaved, "skipped": skipped,
|
|
412
|
-
**({"rules": most_first(rules)} if rules else {})}
|
|
389
|
+
failed_title=failed_title(asked))
|
|
390
|
+
retry = []
|
|
391
|
+
for kind, label in RETRY_GROUPS:
|
|
392
|
+
rows = [row(p, p.get("journal")) for p in papers if held.get(str(p.get("doi") or "").lower()) == kind]
|
|
393
|
+
at = later.get("blocked_at")
|
|
394
|
+
timed = kind == "blocked" and isinstance(at, (int, float)) and not isinstance(at, bool) and at > 0
|
|
395
|
+
if rows:
|
|
396
|
+
retry.append(group(f"{time.strftime('%H:%M', time.localtime(at))} 再试 · {label}" if timed else label, rows))
|
|
397
|
+
return {"ok": first_open(saved), "failed": missing, "left": first_open(left), "retry": first_open(retry)}
|
|
413
398
|
|
|
414
399
|
|
|
415
400
|
# The longest publisher name the hourly-limit notice keeps on one line, in zh and en,
|
|
@@ -430,6 +415,168 @@ def _hourly_hold(state: dict[str, Any], now: float) -> tuple[str, int | None, st
|
|
|
430
415
|
return str(raw.get("publisher") or ""), limit, time.strftime("%H:%M", time.localtime(until))
|
|
431
416
|
|
|
432
417
|
|
|
418
|
+
def _later(state: dict[str, Any], left: int) -> dict[str, Any] | None:
|
|
419
|
+
"""The papers the caller holds for a later try (user, 2026-11-23): 重试 on the running card, its list by why; at most
|
|
420
|
+
those not done (a paper just counted may still be said held). None when none (an older PaperSearch's state)."""
|
|
421
|
+
raw = state.get("later")
|
|
422
|
+
if not isinstance(raw, dict):
|
|
423
|
+
return None
|
|
424
|
+
counts = {kind: _count(raw.get(kind)) for kind in ("no_access", "unexplained", "blocked", "login")}
|
|
425
|
+
held = min(sum(counts.values()), left)
|
|
426
|
+
if not held:
|
|
427
|
+
return None
|
|
428
|
+
at = raw.get("blocked_at")
|
|
429
|
+
timed = counts["blocked"] and isinstance(at, (int, float)) and not isinstance(at, bool) and at > 0
|
|
430
|
+
# When the paused publisher's papers are tried again ("16:58 再试"), the earliest of several.
|
|
431
|
+
return {"total": held, **counts, "blocked_at": time.strftime("%H:%M", time.localtime(at)) if timed else ""}
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
def _switch_note(state: dict[str, Any], now: float) -> str:
|
|
435
|
+
""""换红木兰大学再试" for a few seconds once the batch tries its papers without access with another saved school
|
|
436
|
+
(user, 2026-11-23: on the card's line under its title, in place of the counts and the time)."""
|
|
437
|
+
raw = state.get("switch_note")
|
|
438
|
+
if not isinstance(raw, dict) or not str(raw.get("school") or ""):
|
|
439
|
+
return ""
|
|
440
|
+
at = raw.get("at")
|
|
441
|
+
if not isinstance(at, (int, float)) or isinstance(at, bool) or not 0 <= now - at < SWITCH_SECONDS:
|
|
442
|
+
return ""
|
|
443
|
+
return f"换{raw['school']}再试"
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
#: A file arriving is shown once it has taken this long (a small one comes and goes unshown), and said to have
|
|
447
|
+
#: stopped once no byte has come for this long (user, 2026-11-26).
|
|
448
|
+
TRANSFER_SHOWN_SEC = 3
|
|
449
|
+
TRANSFER_STALLED_SEC = 20
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
def _megabytes(count: float) -> str:
|
|
453
|
+
value = count / (1024 * 1024)
|
|
454
|
+
return f"{value:.0f}" if value >= 100 else f"{value:.1f}"
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def transfer_view(raw: Any, now: float) -> dict[str, Any] | None:
|
|
458
|
+
"""The card's row for a file arriving (progress_reporter.Transfer), or None while there is none or it is
|
|
459
|
+
new: what it is (PDF, or which supplementary file of how many), its share of its size (None when the site
|
|
460
|
+
gave none), what has come in MB, and whether it has stopped (nothing for TRANSFER_STALLED_SEC; ``said``
|
|
461
|
+
says so on hover). Numbers only on the card, the same in every language (user, 2026-11-26)."""
|
|
462
|
+
if not isinstance(raw, dict):
|
|
463
|
+
return None
|
|
464
|
+
try:
|
|
465
|
+
started, at = float(raw["started"]), float(raw["at"])
|
|
466
|
+
done, size = max(0, int(raw.get("done") or 0)), max(0, int(raw.get("size") or 0))
|
|
467
|
+
except (KeyError, TypeError, ValueError):
|
|
468
|
+
return None
|
|
469
|
+
if now - started < TRANSFER_SHOWN_SEC:
|
|
470
|
+
return None
|
|
471
|
+
known = 0 < size and done <= size # a compressed answer may bring more than its stated size
|
|
472
|
+
quiet = max(0.0, now - at)
|
|
473
|
+
kind = "supplement" if raw.get("kind") == "supplement" else "pdf"
|
|
474
|
+
index, count = _count(raw.get("index")), _count(raw.get("count"))
|
|
475
|
+
stalled = quiet >= TRANSFER_STALLED_SEC
|
|
476
|
+
return {"kind": kind, "label": "PDF" if kind == "pdf" else (f"{index}/{count}" if index and count else ""),
|
|
477
|
+
"share": round(100 * done / size, 1) if known else None,
|
|
478
|
+
"amount": f"{_megabytes(done)} / {_megabytes(size)} MB" if known else f"{_megabytes(done)} MB",
|
|
479
|
+
"stalled": stalled, "said": f"{int(quiet)} 秒没有新数据" if stalled else "",
|
|
480
|
+
"name": str(raw.get("name") or "")[:120]}
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def _step(state: dict[str, Any]) -> tuple[dict[str, Any] | None, tuple[str, ...]]:
|
|
484
|
+
"""A running paper's step on the card (None: none to show) and the steps it is among, from its part and stage."""
|
|
485
|
+
part_key = str(state.get("part") or "")
|
|
486
|
+
stage = str(state.get("stage") or "")
|
|
487
|
+
if part_key == "markdown":
|
|
488
|
+
# Its steps as a PDF's are shown, up to the page's read (it had none, 2026-11-16).
|
|
489
|
+
if state.get("page_reading"):
|
|
490
|
+
return {"index": 2, "label": "读全文网页"}, MARKDOWN_STEPS
|
|
491
|
+
if stage == "access_ready":
|
|
492
|
+
return {"index": 2, "label": "全文网页已读取"}, MARKDOWN_STEPS
|
|
493
|
+
if stage in STAGE_STEP and STAGE_STEP[stage][0] <= 1:
|
|
494
|
+
index, label = STAGE_STEP[stage]
|
|
495
|
+
return {"index": index, "label": label}, MARKDOWN_STEPS
|
|
496
|
+
return None, MARKDOWN_STEPS
|
|
497
|
+
if part_key == "supplements":
|
|
498
|
+
found = state.get("supplements_total")
|
|
499
|
+
label = (f"补充材料 {_count(state.get('supplements_saved'))}/{found}"
|
|
500
|
+
if isinstance(found, int) else "查找补充材料")
|
|
501
|
+
return {"index": 4, "label": label}, STEPS
|
|
502
|
+
if part_key == "main" and stage in STAGE_STEP:
|
|
503
|
+
index, label = STAGE_STEP[stage]
|
|
504
|
+
return {"index": index, "label": label}, STEPS
|
|
505
|
+
return None, STEPS
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
def _prompt(item: dict[str, Any], now: float, more: int) -> dict[str, Any]:
|
|
509
|
+
"""What a reminder asks of the user, short (the capsule's words), with its countdown; ``more``: the others."""
|
|
510
|
+
message = str(item.get("message") or "请查看浏览器,可能需要手动操作")
|
|
511
|
+
# The surrounding SSO/verification stage is not evidence of the action
|
|
512
|
+
# being requested. In particular, an idle page is not a school login.
|
|
513
|
+
short = ("页面暂时无进展" if "无进展" in message or "没有进展" in message else
|
|
514
|
+
"请选择学校" if "选择学校" in message else
|
|
515
|
+
"请登录学校" if "登录" in message else
|
|
516
|
+
"请完成验证" if "验证" in message else "需要你处理")
|
|
517
|
+
if message.startswith("学校登录页只能用") and "扫码登录" in message:
|
|
518
|
+
app = message.split("只能用", 1)[1].split("扫码登录", 1)[0]
|
|
519
|
+
short = {"微信": "请用微信扫码", "企业微信": "请用企业微信扫码", "钉钉": "请用钉钉扫码"}.get(app, "请在浏览器扫码登录")
|
|
520
|
+
elif message == "学校登录页只能用短信验证码登录,请在浏览器窗口完成。":
|
|
521
|
+
short = "请用短信验证码登录"
|
|
522
|
+
elif message == "学校登录页需要扫码或短信验证,请在浏览器窗口完成。":
|
|
523
|
+
short = "请完成扫码或短信验证"
|
|
524
|
+
deadline = item.get("deadline")
|
|
525
|
+
remaining = (max(0, int(deadline - now))
|
|
526
|
+
if isinstance(deadline, (int, float)) and not isinstance(deadline, bool) else None)
|
|
527
|
+
ways = [str(way) for way in item.get("ways") or [] if str(way)]
|
|
528
|
+
if ways:
|
|
529
|
+
short = "选择登录方式" # picked in the window itself (user, 2026-11-29)
|
|
530
|
+
prompt = {"message": message, "short": short, "more": more,
|
|
531
|
+
"remaining": fmt_clock(remaining) if remaining is not None else "",
|
|
532
|
+
"login": short in ("请登录学校", "选择登录方式") or message.startswith("学校登录页")}
|
|
533
|
+
if ways:
|
|
534
|
+
prompt.update(ways=ways, school=str(item.get("school") or ""))
|
|
535
|
+
return prompt
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
def _notice(state: dict[str, Any], now: float) -> str:
|
|
539
|
+
"""The download's answer to a click on this paper, for NOTICE_SECONDS."""
|
|
540
|
+
raw = state.get("notice")
|
|
541
|
+
if isinstance(raw, dict) and str(raw.get("current") or "") == str(state.get("current") or ""):
|
|
542
|
+
try:
|
|
543
|
+
if now - float(raw.get("at") or 0) < NOTICE_SECONDS:
|
|
544
|
+
return str(raw.get("text") or "")
|
|
545
|
+
except (TypeError, ValueError):
|
|
546
|
+
pass
|
|
547
|
+
return ""
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
def _papers(state: dict[str, Any], attention: list[dict[str, Any]], now: float) -> list[dict[str, Any]]:
|
|
551
|
+
"""并行下载 (user, 2026-11-29): the papers downloading at once, a row each on the card from two on (one alone is
|
|
552
|
+
the card's own paper): its journal and title, its step, the file arriving or its line, the download's answer to a
|
|
553
|
+
click, and what it asks of the user (``ask``). The one asking first, the others in their windows' order, so that a
|
|
554
|
+
row stays where it is while its paper runs."""
|
|
555
|
+
raw = state.get("papers")
|
|
556
|
+
if not isinstance(raw, dict) or len(raw) < 2:
|
|
557
|
+
return []
|
|
558
|
+
rows = []
|
|
559
|
+
for window, paper in sorted(raw.items(), key=lambda item: int(item[0]) if str(item[0]).isdigit() else 0):
|
|
560
|
+
if not isinstance(paper, dict):
|
|
561
|
+
continue
|
|
562
|
+
current = str(paper.get("current") or "")
|
|
563
|
+
asking = [item for item in attention if current and str(item.get("current") or "").lower() == current.lower()]
|
|
564
|
+
step, steps = (None, STEPS) if asking else _step(paper)
|
|
565
|
+
journal, publisher = str(paper.get("journal") or ""), str(paper.get("publisher") or "")
|
|
566
|
+
transfer = None if asking else transfer_view(paper.get("transfer"), now)
|
|
567
|
+
rows.append({
|
|
568
|
+
"window": str(window), "current": current, "title": str(paper.get("title") or ""),
|
|
569
|
+
"journal": journal or publisher.removeprefix("site:") or current,
|
|
570
|
+
"step": step, "steps": list(steps), "transfer": transfer,
|
|
571
|
+
# Neither a step nor a file: what it is doing ("没权限,换××"), without the part the card's line names.
|
|
572
|
+
"line": "" if asking or step or transfer else str(paper.get("phase") or "")
|
|
573
|
+
or STAGE_TEXT.get(str(paper.get("stage") or ""), ""),
|
|
574
|
+
"notice": _notice(paper, now),
|
|
575
|
+
"ask": _prompt(asking[-1], now, len(asking) - 1) if asking else None,
|
|
576
|
+
})
|
|
577
|
+
return sorted(rows, key=lambda row: row["ask"] is None)
|
|
578
|
+
|
|
579
|
+
|
|
433
580
|
def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
434
581
|
"""Everything the capsule shows for one snapshot of the progress file.
|
|
435
582
|
|
|
@@ -451,7 +598,7 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
451
598
|
awaiting = bool(state.get("awaiting_next"))
|
|
452
599
|
# Publishers whose school login stopped working mid-batch, held by the caller:
|
|
453
600
|
# a line and a button to go on with them once the user is back (2026-11-15).
|
|
454
|
-
held = [{"key": str(entry.get("key")), "name": str(entry.get("name") or entry.get("key")),
|
|
601
|
+
held = [{"key": str(entry.get("key")), "name": str(entry.get("name") or entry.get("key")).removeprefix("site:"),
|
|
455
602
|
"count": int(entry.get("count") or 0)}
|
|
456
603
|
for entry in (state.get("held") or []) if running and isinstance(entry, dict) and entry.get("key")]
|
|
457
604
|
# Nothing else left: the batch waits for the user, which the collapsed capsule says
|
|
@@ -476,70 +623,32 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
476
623
|
mode, tone, headline = "done", "ok", "下载完成"
|
|
477
624
|
|
|
478
625
|
part_key = str(state.get("part") or "")
|
|
479
|
-
if running and not awaiting
|
|
626
|
+
papers = _papers(state, attention, now) if running and not awaiting else []
|
|
627
|
+
# Papers listed: what the batch fetches, not the part one of them is at.
|
|
628
|
+
if running and not awaiting and part_key in PARTS and not papers:
|
|
480
629
|
part = CONTENT_LABELS[part_key]
|
|
481
630
|
else:
|
|
482
631
|
part = content_label(str(state.get("content") or "main"), bool(state.get("markdown")))
|
|
483
632
|
# Before any publisher (the caller's open-access stretch), the channel stands in.
|
|
484
633
|
publisher = str(state.get("publisher") or "") or str(state.get("channel") or "")
|
|
485
634
|
journal = str(state.get("journal") or "")
|
|
635
|
+
# A site without rules of its own runs under "site:<domain>" (publishers/site.py), a name never shown: its journal
|
|
636
|
+
# names it, else its domain (user, 2026-11-24: "site:bristoluniversitypressdigital.com" on the capsule, often).
|
|
637
|
+
if publisher.startswith("site:"):
|
|
638
|
+
publisher = journal or publisher[len("site:"):]
|
|
486
639
|
current = str((attention[-1].get("current") if attention else "") or state.get("current") or "")
|
|
487
640
|
title = str(state.get("title") or "")
|
|
488
641
|
if held_wait:
|
|
489
642
|
publisher = journal = current = title = "" # the last paper is over
|
|
490
643
|
|
|
491
|
-
step = None
|
|
492
|
-
steps = STEPS
|
|
493
|
-
if running and not attention and not awaiting:
|
|
494
|
-
if part_key == "markdown":
|
|
495
|
-
# Its steps as a PDF's are shown, up to the page's read (it had none, 2026-11-16).
|
|
496
|
-
steps = MARKDOWN_STEPS
|
|
497
|
-
stage = str(state.get("stage") or "")
|
|
498
|
-
if state.get("page_reading"):
|
|
499
|
-
step = {"index": 2, "label": "读全文网页"}
|
|
500
|
-
elif stage == "access_ready":
|
|
501
|
-
step = {"index": 2, "label": "全文网页已读取"}
|
|
502
|
-
elif stage in STAGE_STEP and STAGE_STEP[stage][0] <= 1:
|
|
503
|
-
index, label = STAGE_STEP[stage]
|
|
504
|
-
step = {"index": index, "label": label}
|
|
505
|
-
elif part_key == "supplements":
|
|
506
|
-
found = state.get("supplements_total")
|
|
507
|
-
label = (f"补充材料 {_count(state.get('supplements_saved'))}/{found}"
|
|
508
|
-
if isinstance(found, int) else "查找补充材料")
|
|
509
|
-
step = {"index": 4, "label": label}
|
|
510
|
-
elif part_key == "main" and str(state.get("stage") or "") in STAGE_STEP:
|
|
511
|
-
index, label = STAGE_STEP[str(state.get("stage"))]
|
|
512
|
-
step = {"index": index, "label": label}
|
|
644
|
+
step, steps = _step(state) if running and not attention and not awaiting else (None, STEPS)
|
|
513
645
|
|
|
514
646
|
started = _time(state.get("started_at"))
|
|
515
647
|
ended = now if running else _time(state.get("finished_at"))
|
|
516
648
|
elapsed = fmt_clock(ended - started) if started is not None and ended is not None else ""
|
|
517
649
|
|
|
518
|
-
prompt = None
|
|
519
|
-
|
|
520
|
-
item = attention[-1]
|
|
521
|
-
message = str(item.get("message") or "请查看浏览器,可能需要手动操作")
|
|
522
|
-
# The surrounding SSO/verification stage is not evidence of the action
|
|
523
|
-
# being requested. In particular, an idle page is not a school login.
|
|
524
|
-
short = ("页面暂时无进展" if "无进展" in message or "没有进展" in message else
|
|
525
|
-
"请选择学校" if "选择学校" in message else
|
|
526
|
-
"请登录学校" if "登录" in message else
|
|
527
|
-
"请完成验证" if "验证" in message else "需要你处理")
|
|
528
|
-
deadline = item.get("deadline")
|
|
529
|
-
remaining = (max(0, int(deadline - now))
|
|
530
|
-
if isinstance(deadline, (int, float)) and not isinstance(deadline, bool) else None)
|
|
531
|
-
prompt = {"message": message, "short": short, "more": len(attention) - 1,
|
|
532
|
-
"remaining": fmt_clock(remaining) if remaining is not None else "",
|
|
533
|
-
"login": short == "请登录学校"}
|
|
534
|
-
|
|
535
|
-
notice = ""
|
|
536
|
-
raw = state.get("notice")
|
|
537
|
-
if isinstance(raw, dict) and str(raw.get("current") or "") == str(state.get("current") or ""):
|
|
538
|
-
try:
|
|
539
|
-
if now - float(raw.get("at") or 0) < NOTICE_SECONDS:
|
|
540
|
-
notice = str(raw.get("text") or "")
|
|
541
|
-
except (TypeError, ValueError):
|
|
542
|
-
pass
|
|
650
|
+
prompt = _prompt(attention[-1], now, len(attention) - 1) if attention else None
|
|
651
|
+
notice = _notice(state, now)
|
|
543
652
|
# Held by the hourly limit the user set: the capsule and the card say so, and that
|
|
544
653
|
# it is the user's setting, not the publisher's (2026-11-12).
|
|
545
654
|
line = status_text(state, running) if running else ""
|
|
@@ -567,10 +676,13 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
567
676
|
"ok": ok, "bad": bad, "left": max(0, total - done) if running and total else None,
|
|
568
677
|
"stopped": stopped,
|
|
569
678
|
"part": part, "publisher": publisher,
|
|
570
|
-
|
|
679
|
+
# A journal named as its publisher (Science, JAMA, BMJ, PNAS) once (user, 2026-11-23).
|
|
680
|
+
"where": " · ".join(v for v in (journal, "" if publisher.casefold() == journal.casefold() else publisher) if v),
|
|
571
681
|
"title": title, "current": current,
|
|
572
682
|
"run_id": str(state.get("run_id") or ""),
|
|
573
683
|
"step": step, "steps": list(steps), "line": line,
|
|
684
|
+
"transfer": transfer_view(state.get("transfer"), now) if running and not attention and not awaiting and not hold else None,
|
|
685
|
+
"papers": papers,
|
|
574
686
|
"elapsed": elapsed, "attention": prompt, "notice": notice, "hold": bool(hold),
|
|
575
687
|
"completion_detail": str(state.get("phase") or "")
|
|
576
688
|
if not running and state.get("stage") == "supplements_checked" else "",
|
|
@@ -583,6 +695,8 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
583
695
|
and (not awaiting or bool(state.get("browser_pid") or state.get("browser_pids"))),
|
|
584
696
|
"stop_left": max(0, total - done - 1),
|
|
585
697
|
"held": held, "held_wait": held_wait,
|
|
698
|
+
"later": _later(state, max(0, total - done)) if running else None,
|
|
699
|
+
"switch_note": _switch_note(state, now) if running else "",
|
|
586
700
|
"folder": bool(state.get("output_dir")),
|
|
587
701
|
}
|
|
588
702
|
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
"name": "IOP",
|
|
5
5
|
"article_url_template": "https://iopscience.iop.org/article/{doi}",
|
|
6
6
|
"pdf_url_templates": [
|
|
7
|
-
"https://iopscience.iop.org/article/{doi}/pdf"
|
|
7
|
+
"https://iopscience.iop.org/article/{doi}/pdf",
|
|
8
|
+
"https://iopscience.iop.org/article/{doi}/ampdf"
|
|
8
9
|
],
|
|
9
10
|
"success_url_markers": [
|
|
10
11
|
"iopscience.iop.org/article/"
|
|
@@ -6,14 +6,16 @@
|
|
|
6
6
|
"10.1212"
|
|
7
7
|
],
|
|
8
8
|
"base_domains": [
|
|
9
|
-
"neurology.org"
|
|
9
|
+
"neurology.org",
|
|
10
|
+
"continuum.aan.com"
|
|
10
11
|
],
|
|
11
12
|
"article_url_template": "https://doi.org/{doi}",
|
|
12
13
|
"pdf_url_templates": [
|
|
13
14
|
"https://www.neurology.org/doi/pdf/{doi}"
|
|
14
15
|
],
|
|
15
16
|
"success_url_markers": [
|
|
16
|
-
"neurology.org/doi/"
|
|
17
|
+
"neurology.org/doi/",
|
|
18
|
+
"continuum.aan.com/doi/"
|
|
17
19
|
],
|
|
18
20
|
"auth_url_markers": [
|
|
19
21
|
"/login",
|
|
@@ -16,7 +16,7 @@ from typing import ClassVar
|
|
|
16
16
|
from urllib.parse import urlparse
|
|
17
17
|
|
|
18
18
|
from ..engine.access_rules import registrable_domain
|
|
19
|
-
from .model import PublisherProfile
|
|
19
|
+
from .model import PdfSourcePathTemplate, PublisherProfile
|
|
20
20
|
|
|
21
21
|
#: Name prefix of a run-time site profile: ``site:<registrable domain>``.
|
|
22
22
|
SITE_PREFIX = "site:"
|
|
@@ -34,11 +34,17 @@ GENERIC_SUPPLEMENTARY_URL_MARKERS = ("supplementary", "suppl_file", "supporting-
|
|
|
34
34
|
# Where a DOI can land that is no publisher's site: doi.org itself, Crossref's
|
|
35
35
|
# multiple-resolution chooser, the Handle resolver.
|
|
36
36
|
_NOT_A_SITE = frozenset({"doi.org", "crossref.org", "handle.net"})
|
|
37
|
-
# Platforms the engine does not sign in on, whatever DOI leads there: ClinicalKey
|
|
38
|
-
# (the Elsevier adapter's unsupported
|
|
37
|
+
# Platforms the engine does not sign in on, whatever DOI leads there: ClinicalKey and
|
|
38
|
+
# EM-Consulte (the Elsevier adapter's unsupported platforms) and the databases dropped on
|
|
39
39
|
# 2026-11-02 (CNKI, Wanfang, VIP).
|
|
40
|
-
_UNSUPPORTED_SITES = re.compile(
|
|
40
|
+
_UNSUPPORTED_SITES = re.compile(
|
|
41
|
+
r"clinicalkey\.[a-z]{2,3}(?:\.[a-z]{2})?|em-consulte\.com|cnki\.net|wanfangdata\.com\.cn|cqvip\.com")
|
|
41
42
|
_DOI_PREFIX = re.compile(r"10\.\d{4,9}")
|
|
43
|
+
# A platform's PDF address made from the article page's address, by DOI prefix. F1000's open research
|
|
44
|
+
# platforms (F1000Research, Wellcome, Gates, Bioethics Open Research and the others, all 10.12688): the
|
|
45
|
+
# page /articles/<n>-<n>/v<k> plus /pdf, a redirect to the file. The page names no PDF anywhere (its
|
|
46
|
+
# Download button opens a menu), and nothing was tried there (Bioethics Open Research, 2026-11-24).
|
|
47
|
+
_PAGE_PDF_PATHS = {"10.12688": ("/articles/", "{source_path}/pdf")}
|
|
42
48
|
|
|
43
49
|
|
|
44
50
|
@dataclass(frozen=True)
|
|
@@ -73,6 +79,7 @@ def site_profile(doi: str, landing_url: str) -> SiteProfile | None:
|
|
|
73
79
|
domain = registrable_domain(host)
|
|
74
80
|
if not domain or domain in _NOT_A_SITE or _UNSUPPORTED_SITES.fullmatch(domain):
|
|
75
81
|
return None
|
|
82
|
+
page_pdf = _PAGE_PDF_PATHS.get(prefix)
|
|
76
83
|
return SiteProfile(
|
|
77
84
|
name=SITE_PREFIX + domain,
|
|
78
85
|
article_url_template="https://doi.org/{doi}",
|
|
@@ -82,5 +89,6 @@ def site_profile(doi: str, landing_url: str) -> SiteProfile | None:
|
|
|
82
89
|
sso_text_markers=GENERIC_SSO_TEXT_MARKERS,
|
|
83
90
|
doi_prefixes=(prefix,),
|
|
84
91
|
base_domains=(domain,),
|
|
92
|
+
pdf_source_path_templates=(PdfSourcePathTemplate(domain, *page_pdf),) if page_pdf else (),
|
|
85
93
|
supplementary_url_markers=GENERIC_SUPPLEMENTARY_URL_MARKERS,
|
|
86
94
|
)
|
|
@@ -13,6 +13,7 @@ the same article again.
|
|
|
13
13
|
"""
|
|
14
14
|
from __future__ import annotations
|
|
15
15
|
|
|
16
|
+
import threading
|
|
16
17
|
import time
|
|
17
18
|
from pathlib import Path
|
|
18
19
|
|
|
@@ -20,6 +21,9 @@ from .entitlements import _data_dir, _read_json, _write_json
|
|
|
20
21
|
|
|
21
22
|
HOUR = 3600
|
|
22
23
|
DEFAULT_LIMIT = 100
|
|
24
|
+
#: A batch's windows open articles at once (并行下载, user 2026-11-29): the check and the count are one step under it, so
|
|
25
|
+
#: that a publisher's windows together stay within its limit and none of their counts is lost.
|
|
26
|
+
_LOCK = threading.RLock()
|
|
23
27
|
|
|
24
28
|
|
|
25
29
|
def ledger_path() -> Path:
|
|
@@ -64,9 +68,28 @@ def record(key: str, now: float | None = None) -> None:
|
|
|
64
68
|
"""Count one article opened on ``key``'s site, in its hour or in a new one; hours over are dropped."""
|
|
65
69
|
if not key:
|
|
66
70
|
return
|
|
67
|
-
|
|
71
|
+
with _LOCK:
|
|
72
|
+
_record(key, time.time() if now is None else now)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _record(key: str, now: float) -> None:
|
|
68
76
|
data = _read_json(ledger_path())
|
|
69
77
|
kept = {name: {"start": hour[0], "count": hour[1]} for name in data if (hour := _hour(data, name, now))}
|
|
70
78
|
current = kept.get(key, {"start": now, "count": 0})
|
|
71
79
|
kept[key] = {"start": current["start"], "count": current["count"] + 1}
|
|
72
80
|
_write_json(ledger_path(), kept)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def take(key: str, limit: int, now: float | None = None) -> int:
|
|
84
|
+
"""Open one more article on ``key``'s site if its hour allows: 0, and it is counted; else the seconds to wait
|
|
85
|
+
(``wait_seconds``), nothing counted. One step, so that windows opening articles at once never pass the limit."""
|
|
86
|
+
if not key:
|
|
87
|
+
return 0
|
|
88
|
+
with _LOCK:
|
|
89
|
+
wait = wait_seconds(key, limit) if now is None else wait_seconds(key, limit, now)
|
|
90
|
+
if not wait:
|
|
91
|
+
if now is None:
|
|
92
|
+
record(key)
|
|
93
|
+
else:
|
|
94
|
+
record(key, now)
|
|
95
|
+
return wait
|