papersearch 0.7.2 → 0.8.0
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/LICENSE-paper-search-mcp-nodejs +24 -0
- package/NOTICE +8 -37
- package/README.en.md +7 -3
- package/README.fr.md +268 -0
- package/README.ja.md +268 -0
- package/README.ko.md +268 -0
- package/README.md +7 -3
- package/README.zh-Hant.md +268 -0
- package/dist/capabilities/download/batch/batch.d.ts +16 -1
- package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batch.js +669 -53
- 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 +4 -3
- package/dist/capabilities/download/batch/batchFolder.js.map +1 -1
- package/dist/capabilities/download/batch/batchSummary.js +1 -1
- package/dist/capabilities/download/batch/batchSummary.js.map +1 -1
- package/dist/capabilities/download/batch/networkLoss.d.ts +12 -3
- package/dist/capabilities/download/batch/networkLoss.d.ts.map +1 -1
- package/dist/capabilities/download/batch/networkLoss.js +25 -4
- 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/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 +27 -15
- 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 +42 -2
- 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/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/runlog/RunLedger.d.ts +7 -0
- package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.js +13 -0
- package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts +17 -9
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +89 -56
- 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 +107 -59
- package/dist/infrastructure/school/SchoolAttempt.js.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.d.ts +7 -2
- package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.js +30 -7
- 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 +2 -0
- package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolReadiness.js +2 -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 +52 -3
- package/dist/infrastructure/school/types.d.ts.map +1 -1
- package/dist/infrastructure/school/types.js.map +1 -1
- package/dist/management/failures/index.d.ts +28 -2
- package/dist/management/failures/index.d.ts.map +1 -1
- package/dist/management/failures/index.js +83 -21
- package/dist/management/failures/index.js.map +1 -1
- package/package.json +7 -2
- 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 +18 -0
- 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 +2 -9
- package/school/paper_search_school/adapters/oup/__init__.py +27 -4
- package/school/paper_search_school/adapters/platforms/__init__.py +4 -1
- package/school/paper_search_school/adapters/platforms/atypon/__init__.py +8 -0
- package/school/paper_search_school/adapters/platforms/jstage/__init__.py +64 -0
- package/school/paper_search_school/adapters/sage/__init__.py +4 -1
- package/school/paper_search_school/adapters/thieme/__init__.py +6 -11
- 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 +274 -158
- package/school/paper_search_school/assets/capsule_en.json +99 -98
- package/school/paper_search_school/assets/capsule_fr.json +100 -99
- package/school/paper_search_school/assets/capsule_ja.json +99 -98
- package/school/paper_search_school/assets/capsule_ko.json +99 -98
- package/school/paper_search_school/assets/capsule_zh-Hant.json +94 -97
- package/school/paper_search_school/browser/batch_session.py +1 -1
- package/school/paper_search_school/browser/challenge/__init__.py +12 -9
- package/school/paper_search_school/browser/challenge/continuation.py +65 -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 +100 -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/services/__init__.py +1 -0
- package/school/paper_search_school/browser/challenge/services/solver.py +272 -0
- package/school/paper_search_school/cli_config.py +10 -5
- package/school/paper_search_school/cold_start.py +22 -11
- package/school/paper_search_school/config.py +11 -10
- package/school/paper_search_school/download_diagnostics.py +7 -2
- package/school/paper_search_school/engine/access_rules.py +15 -5
- package/school/paper_search_school/engine/batch.py +55 -15
- package/school/paper_search_school/engine/batch_access.py +59 -21
- package/school/paper_search_school/engine/batch_capture.py +215 -18
- 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 +168 -32
- package/school/paper_search_school/engine/batch_login.py +223 -16
- package/school/paper_search_school/engine/batch_pdf_urls.py +38 -7
- package/school/paper_search_school/engine/batch_waits.py +179 -12
- package/school/paper_search_school/engine/bridge.py +44 -7
- package/school/paper_search_school/engine/fulltext_page.py +45 -7
- package/school/paper_search_school/engine/router.py +18 -2
- package/school/paper_search_school/entitlements.py +1 -1
- package/school/paper_search_school/orchestrator.py +44 -18
- package/school/paper_search_school/pdf_utils.py +25 -16
- package/school/paper_search_school/progress_capsule.py +36 -6
- package/school/paper_search_school/progress_reporter.py +71 -13
- package/school/paper_search_school/progress_view.py +64 -44
- 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/builtin/sage.json +4 -2
- package/school/paper_search_school/publishers/builtin/thieme.json +3 -1
- package/school/paper_search_school/publishers/site.py +12 -4
- package/school/paper_search_school/school_switch.py +34 -52
- package/school/paper_search_school/school_test.py +1 -1
- package/school/paper_search_school/server.py +24 -11
- package/school/paper_search_school/user_settings.py +13 -0
- package/school/pyproject.toml +1 -0
- package/skills/paper-search/SKILL.md +107 -107
- package/skills/paper-search/references/browser-download.md +102 -101
- 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/school/paper_search_school/browser/challenge/prompt.py +0 -154
|
@@ -115,14 +115,19 @@ def _download_impl(doi: str, output_dir: str | Path | None, *,
|
|
|
115
115
|
login_only: bool = False, login_wait: int | None = None,
|
|
116
116
|
fulltext: str | None = None, school: str | None = None, fresh: bool = False) -> dict[str, Any]:
|
|
117
117
|
config = load_config()
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
# school is not changed (user, 2026-11-17).
|
|
121
|
-
from .schools.saved import use_for_download
|
|
118
|
+
from . import school_switch
|
|
119
|
+
from .schools import saved as saved_schools
|
|
122
120
|
|
|
123
|
-
|
|
121
|
+
# Another saved school for this download alone (the user asked, or a batch's 没权限 tried with it at its end); the
|
|
122
|
+
# config's own school is not changed (user, 2026-11-17).
|
|
123
|
+
other_school = ""
|
|
124
|
+
if school:
|
|
125
|
+
problem = saved_schools.use_for_download(config, school)
|
|
124
126
|
if problem:
|
|
125
127
|
return fail(doi, problem, error_type=problem, action="review_school")
|
|
128
|
+
if not saved_schools.is_current(load_config(), saved_schools.current(config) or {}):
|
|
129
|
+
other_school = school_switch.name(saved_schools.current(config) or {})
|
|
130
|
+
config[school_switch.MARKS_OFF] = True
|
|
126
131
|
if fulltext:
|
|
127
132
|
# The article's full-text page is saved while on it (engine/fulltext_page.py).
|
|
128
133
|
# A main text already cached is not fetched again, so neither is its page.
|
|
@@ -169,19 +174,31 @@ def _download_impl(doi: str, output_dir: str | Path | None, *,
|
|
|
169
174
|
log.info(f"paper-search-school - {doi}")
|
|
170
175
|
# Another school than the one the browser last signed in with: that sign-in forgotten first; a test
|
|
171
176
|
# (``fresh``) always starts signed out, so that the account is what it tries (user, 2026-11-21).
|
|
172
|
-
from .cold_start import before_sign_in
|
|
173
|
-
from . import
|
|
174
|
-
from .schools import saved as saved_schools
|
|
177
|
+
from .cold_start import before_sign_in, signed_in_school
|
|
178
|
+
from .progress_reporter import batch_id
|
|
175
179
|
|
|
176
|
-
# 没权限时换下一所学校 (school_switch.py): the schools to try in turn,
|
|
177
|
-
#
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
saved_schools.apply(config, turns[0])
|
|
180
|
+
# 没权限时换下一所学校 (school_switch.py): the schools to try in turn, the default one first. One alone: the switch
|
|
181
|
+
# off, a school named for this download, the test of one, a sign-in only, a paper of a batch (it switches once, at
|
|
182
|
+
# its end, for all its papers without access: user, 2026-11-22).
|
|
183
|
+
turns = (school_switch.schools(config) if school_switch.enabled(config) and not school and not fresh
|
|
184
|
+
and not login_only and not batch_id() else [])
|
|
182
185
|
turn = 0
|
|
186
|
+
entry_turn = 0
|
|
183
187
|
while True:
|
|
188
|
+
entity = str(config.get("idp_entity_id") or "").strip()
|
|
189
|
+
if not fresh and entity and signed_in_school() not in ("", entity):
|
|
190
|
+
# The batch's own browser, open from the article before, holds the profile: the default school's article
|
|
191
|
+
# after one another school got kept that school's sign-in beside its own, each article waiting 10 s for the
|
|
192
|
+
# profile in vain (Windows, 2026-11-22: Bone signed in with the default school, the other school's Wiley sign-in still
|
|
193
|
+
# there). Closed first, as for a switch.
|
|
194
|
+
from .browser.batch_session import active_batch
|
|
195
|
+
|
|
196
|
+
batch = active_batch.get()
|
|
197
|
+
if batch is not None:
|
|
198
|
+
batch.close()
|
|
184
199
|
signed = before_sign_in(config, always=fresh)
|
|
200
|
+
if signed == "busy" and not fresh:
|
|
201
|
+
log.info(" [Institutional] the download browser is open: the last school's sign-in kept")
|
|
185
202
|
if signed == "cleared":
|
|
186
203
|
log.info(" [Institutional] the browser's sign-in with another school forgotten")
|
|
187
204
|
elif signed == "busy" and fresh:
|
|
@@ -192,6 +209,15 @@ def _download_impl(doi: str, output_dir: str | Path | None, *,
|
|
|
192
209
|
except Exception as exc:
|
|
193
210
|
log.info(f" [Institutional] route exception: {type(exc).__name__}")
|
|
194
211
|
return fail(doi, "institutional route raised", error_type="source_exception", action="review_logs")
|
|
212
|
+
# The school's entries by one name: the next one, with this school, when the one chosen did not do.
|
|
213
|
+
if school_switch.entry_did_not_do(result) and entry_turn + 1 < int(result.get("same_name_entries") or 0):
|
|
214
|
+
entry_turn += 1
|
|
215
|
+
config["institution_entry_turn"] = entry_turn
|
|
216
|
+
log.info(f" [Institutional] the school's entry {entry_turn} of {result['same_name_entries']} did not do; "
|
|
217
|
+
f"the next one")
|
|
218
|
+
continue
|
|
219
|
+
entry_turn = 0
|
|
220
|
+
config.pop("institution_entry_turn", None)
|
|
195
221
|
if turn + 1 >= len(turns) or not school_switch.no_access(result):
|
|
196
222
|
break
|
|
197
223
|
# Signed in, no access: the next school, its sign-in after this one's is forgotten (the batch's browser closed
|
|
@@ -207,14 +233,14 @@ def _download_impl(doi: str, output_dir: str | Path | None, *,
|
|
|
207
233
|
if batch is not None:
|
|
208
234
|
batch.close()
|
|
209
235
|
saved_schools.apply(config, following)
|
|
236
|
+
config[school_switch.MARKS_OFF] = True
|
|
210
237
|
if before_sign_in(config) == "busy":
|
|
211
238
|
log.info(" [Institutional] the browser kept the last school's sign-in; no other school tried")
|
|
212
239
|
turn -= 1
|
|
213
240
|
break
|
|
214
|
-
if
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
result["school"] = school_switch.name(turns[turn]) # not the default school's: the results say whose
|
|
241
|
+
if result and result.get("success") and (turn or other_school):
|
|
242
|
+
# Not the default school's: the results say whose.
|
|
243
|
+
result["school"] = school_switch.name(turns[turn]) if turn else other_school
|
|
218
244
|
elif turns and turn and school_switch.no_access(result):
|
|
219
245
|
result["schools_tried"] = turn + 1 # the lists say "N 所学校都没有权限"
|
|
220
246
|
# An article that re-checked a blocked journal's site: open again unless blocked again.
|
|
@@ -12,11 +12,6 @@ import requests
|
|
|
12
12
|
|
|
13
13
|
from .network import fetch
|
|
14
14
|
|
|
15
|
-
try:
|
|
16
|
-
from bs4 import BeautifulSoup
|
|
17
|
-
except Exception:
|
|
18
|
-
BeautifulSoup = None
|
|
19
|
-
|
|
20
15
|
|
|
21
16
|
def is_pdf_file(path: Path) -> bool:
|
|
22
17
|
try:
|
|
@@ -156,6 +151,13 @@ def iter_urls(obj: Any) -> Any:
|
|
|
156
151
|
|
|
157
152
|
|
|
158
153
|
def extract_pdf_url_from_html(html: str, base_url: str) -> str | None:
|
|
154
|
+
"""The PDF address the page states about itself, or ``None``.
|
|
155
|
+
|
|
156
|
+
Only ``citation_pdf_url``: the page's other links are references, related
|
|
157
|
+
papers and other documents. One guessed from them was a UN ageing-policy PDF
|
|
158
|
+
for a Journal of Global Aging article (2026-11-24), so no address is better
|
|
159
|
+
than a wrong one.
|
|
160
|
+
"""
|
|
159
161
|
urls: list[str] = []
|
|
160
162
|
for match in re.finditer(
|
|
161
163
|
r"""<meta[^>]+name=["']citation_pdf_url["'][^>]+content=["']([^"']+)["']""", html, re.I
|
|
@@ -165,22 +167,29 @@ def extract_pdf_url_from_html(html: str, base_url: str) -> str | None:
|
|
|
165
167
|
r"""<meta[^>]+content=["']([^"']+)["'][^>]+name=["']citation_pdf_url["']""", html, re.I
|
|
166
168
|
):
|
|
167
169
|
urls.append(urllib.parse.urljoin(base_url, match.group(1)))
|
|
168
|
-
if BeautifulSoup is not None:
|
|
169
|
-
soup = BeautifulSoup(html, "html.parser")
|
|
170
|
-
for tag in soup.find_all(["iframe", "embed", "a"]):
|
|
171
|
-
candidate = tag.get("src") or tag.get("href")
|
|
172
|
-
if candidate:
|
|
173
|
-
urls.append(urllib.parse.urljoin(base_url, candidate))
|
|
174
|
-
else:
|
|
175
|
-
for match in re.finditer(r"""(?:src|href)=["']([^"']+)["']""", html, re.I):
|
|
176
|
-
urls.append(urllib.parse.urljoin(base_url, match.group(1)))
|
|
177
|
-
|
|
178
170
|
for url in dedupe(urls):
|
|
179
|
-
|
|
171
|
+
# The page's own declaration, not a guessed link: the plausibility rules
|
|
172
|
+
# above are for links read off a page, and they reject the publisher's
|
|
173
|
+
# own "/journals/…/article-p181.pdf" (Bristol, 2026-11-25).
|
|
174
|
+
if url.startswith(("http://", "https://")) and not url.startswith("data:"):
|
|
180
175
|
return url
|
|
181
176
|
return None
|
|
182
177
|
|
|
183
178
|
|
|
179
|
+
def pdf_links_from_html(html: str, base_url: str) -> list[str]:
|
|
180
|
+
"""Every address in the page that could be a PDF, for the caller to judge.
|
|
181
|
+
|
|
182
|
+
The choice is the caller's, by the same rule its usual address flow uses:
|
|
183
|
+
a link here is only a candidate, not this article's PDF.
|
|
184
|
+
"""
|
|
185
|
+
if not html:
|
|
186
|
+
return []
|
|
187
|
+
urls: list[str] = []
|
|
188
|
+
for match in re.finditer(r"""(?:src|href)=["']([^"']+)["']""", html, re.I):
|
|
189
|
+
urls.append(urllib.parse.urljoin(base_url, match.group(1)))
|
|
190
|
+
return [url for url in dedupe(urls) if is_plausible_pdf_url(url)]
|
|
191
|
+
|
|
192
|
+
|
|
184
193
|
def download_pdf(
|
|
185
194
|
url: str,
|
|
186
195
|
output_path: Path,
|
|
@@ -172,7 +172,7 @@ class Api:
|
|
|
172
172
|
self._mac_drag: _MacDrag | None = None # macOS: presses tracked natively (main)
|
|
173
173
|
self._native_drag = False # this drag follows the mouse natively, not the page
|
|
174
174
|
# papers.json: when read, its batch, the sites not yet supported its pages came from.
|
|
175
|
-
self._papers_seen: tuple[int, str
|
|
175
|
+
self._papers_seen: tuple[int, str] = (0, "")
|
|
176
176
|
self._hovering = False
|
|
177
177
|
self._layout: tuple[int, bool, Rect, Rect] | None = None
|
|
178
178
|
self._closed = False
|
|
@@ -195,15 +195,34 @@ class Api:
|
|
|
195
195
|
# 成功, 失败 and 剩余 open their lists once the caller has sent this batch's papers.
|
|
196
196
|
if snapshot and snapshot.get("batch_id") and self._papers_batch() == snapshot["batch_id"]:
|
|
197
197
|
shown["lists"] = True
|
|
198
|
-
# The sites not yet supported its pages came from: a line while it runs (2026-11-16).
|
|
199
|
-
if shown.get("mode") in ("running", "attention") and self._papers_seen[2]:
|
|
200
|
-
shown["sites"] = self._papers_seen[2]
|
|
201
198
|
except Exception:
|
|
202
199
|
shown = {"mode": "idle"}
|
|
200
|
+
if shown.get("mode") in ("running", "attention"):
|
|
201
|
+
shown["holds"] = self._holds()
|
|
203
202
|
shown["lang"] = self._lang
|
|
204
203
|
request = take_settings_request() # `paper-search-school settings`: show the settings
|
|
205
204
|
return {**shown, "open_settings": request} if request else shown
|
|
206
205
|
|
|
206
|
+
# Read again at most this often: the settings change by hand, the page asks every second.
|
|
207
|
+
_HOLDS_EVERY_SEC = 5.0
|
|
208
|
+
|
|
209
|
+
def _holds(self) -> bool:
|
|
210
|
+
"""Whether a batch may hold papers for a later try, and the card shows 重试 (user, 2026-11-24): 失败后自动重试 on
|
|
211
|
+
(原因不明 at the end, a blocking site after its pause), or 没权限时换下一所学校 on with another saved school. Each
|
|
212
|
+
switch its own; both off, none waits and the card has no 重试, its papers failed at once."""
|
|
213
|
+
cached = getattr(self, "_holds_cache", None)
|
|
214
|
+
if cached and time.time() - cached[0] < self._HOLDS_EVERY_SEC:
|
|
215
|
+
return cached[1]
|
|
216
|
+
try:
|
|
217
|
+
from . import config as _config, school_switch
|
|
218
|
+
loaded = _config.load_config()
|
|
219
|
+
holds = (user_settings.retry_enabled()
|
|
220
|
+
or (school_switch.enabled(loaded) and len(school_switch.schools(loaded)) > 1))
|
|
221
|
+
except Exception:
|
|
222
|
+
holds = True # not known: as before, 重试 shown
|
|
223
|
+
self._holds_cache = (time.time(), bool(holds))
|
|
224
|
+
return bool(holds)
|
|
225
|
+
|
|
207
226
|
# --- watching the task, also while the capsule is minimized ------------
|
|
208
227
|
def watch(self) -> None:
|
|
209
228
|
"""Notifications and closing, off the page: the system slows a minimized
|
|
@@ -336,11 +355,11 @@ class Api:
|
|
|
336
355
|
if changed != self._papers_seen[0]:
|
|
337
356
|
listed = read_papers() or {}
|
|
338
357
|
batch = str(listed.get("batch_id") or "")
|
|
339
|
-
self._papers_seen = (changed, batch
|
|
358
|
+
self._papers_seen = (changed, batch)
|
|
340
359
|
return self._papers_seen[1]
|
|
341
360
|
|
|
342
361
|
def paper_lists(self) -> dict[str, Any]:
|
|
343
|
-
return progress_view.paper_lists(read_papers(), read_state())
|
|
362
|
+
return progress_view.paper_lists(read_papers(), read_state(), self._holds())
|
|
344
363
|
|
|
345
364
|
# --- pages from sites not yet supported (user, 2026-11-16) -------------
|
|
346
365
|
def _batch_papers(self) -> list[dict[str, Any]]:
|
|
@@ -422,6 +441,7 @@ class Api:
|
|
|
422
441
|
"default": f.default, "page": f.page} for f in user_settings.FIELDS],
|
|
423
442
|
"notify": user_settings.notify_enabled(),
|
|
424
443
|
"hourly_now": user_settings.hourly_now(),
|
|
444
|
+
"retry": user_settings.retry_enabled(),
|
|
425
445
|
"download_dir": download_directory.current(),
|
|
426
446
|
"language": self._lang,
|
|
427
447
|
# Whether the settings have the Markdown page (PaperSearch Pro's, edition.py).
|
|
@@ -460,6 +480,16 @@ class Api:
|
|
|
460
480
|
return {"ok": False, "error": f"保存失败:{type(exc).__name__}"}
|
|
461
481
|
return {"ok": True, "hourly_now": enabled}
|
|
462
482
|
|
|
483
|
+
def set_retry(self, enabled: bool) -> dict[str, Any]:
|
|
484
|
+
"""失败后自动重试 saves immediately, like the notification switch (the next batch reads it)."""
|
|
485
|
+
if not isinstance(enabled, bool):
|
|
486
|
+
return {"ok": False, "error": "开关必须为开启或关闭"}
|
|
487
|
+
try:
|
|
488
|
+
user_settings.set_retry(enabled)
|
|
489
|
+
except (OSError, ValueError) as exc:
|
|
490
|
+
return {"ok": False, "error": f"保存失败:{type(exc).__name__}"}
|
|
491
|
+
return {"ok": True, "retry": enabled}
|
|
492
|
+
|
|
463
493
|
# The settings' check of system notifications (user, 2026-11-10): a switch turned on,
|
|
464
494
|
# or a test notification, says when the system keeps them from showing.
|
|
465
495
|
def check_notifications(self) -> dict[str, str]:
|
|
@@ -303,6 +303,7 @@ def _adopt_batch(batch_id: str, total: int, counts: tuple[int | None, int | None
|
|
|
303
303
|
_STATE.update(total=int(total), lanes=fields.get("lanes", ""),
|
|
304
304
|
**({"held": fields["held"]} if "held" in fields else {}),
|
|
305
305
|
**({"held_wait": fields["held_wait"]} if "held_wait" in fields else {}),
|
|
306
|
+
**({"later": fields["later"]} if "later" in fields else {}),
|
|
306
307
|
**({"done": done} if done is not None else {}),
|
|
307
308
|
**({"success": succeeded} if succeeded is not None else {}),
|
|
308
309
|
**({"failed": failed} if failed is not None else {}))
|
|
@@ -347,15 +348,22 @@ def _adopt_batch(batch_id: str, total: int, counts: tuple[int | None, int | None
|
|
|
347
348
|
return True
|
|
348
349
|
|
|
349
350
|
|
|
350
|
-
|
|
351
|
+
def _held_key(value: Any) -> str:
|
|
352
|
+
"""A held publisher's key as the caller sent it, which 登录并继续 sends back unchanged: the
|
|
353
|
+
publisher's name ("Science"), else its DOI prefix ("10.1126/"); empty when it is not one short line.
|
|
354
|
+
The batch keys them by name since 2026-11-17 (a publisher's other DOI prefixes wait with it); a
|
|
355
|
+
check for DOI prefixes alone dropped every one of them, and the window showed no 登录并继续 (2026-11-23)."""
|
|
356
|
+
if not isinstance(value, str) or not 0 < len(value) <= 120 or not value.isprintable() or value != value.strip():
|
|
357
|
+
return ""
|
|
358
|
+
return value
|
|
351
359
|
|
|
352
360
|
|
|
353
361
|
def _held(raw: Any) -> list[dict[str, Any]]:
|
|
354
362
|
"""The publishers whose papers the caller holds (their school login stopped working
|
|
355
|
-
mid-batch): [{key (
|
|
363
|
+
mid-batch): [{key (``_held_key``), name, count}], at most four, checked for the window."""
|
|
356
364
|
held: list[dict[str, Any]] = []
|
|
357
365
|
for entry in raw if isinstance(raw, list) else []:
|
|
358
|
-
if not isinstance(entry, dict) or not
|
|
366
|
+
if not isinstance(entry, dict) or not _held_key(entry.get("key")):
|
|
359
367
|
continue
|
|
360
368
|
count = entry.get("count")
|
|
361
369
|
if not isinstance(count, int) or isinstance(count, bool) or not 0 < count <= 1_000_000:
|
|
@@ -365,10 +373,35 @@ def _held(raw: Any) -> list[dict[str, Any]]:
|
|
|
365
373
|
return held[:4]
|
|
366
374
|
|
|
367
375
|
|
|
376
|
+
#: Why the caller holds a paper for a later try (``sync_batch``'s ``later``).
|
|
377
|
+
LATER_KINDS = ("no_access", "unexplained", "blocked", "login")
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def _later(raw: Any) -> dict[str, Any]:
|
|
381
|
+
"""The papers the caller holds for a later try, by why (LATER_KINDS), and when the blocked ones are tried
|
|
382
|
+
again (``blocked_at``, epoch seconds), checked for the window."""
|
|
383
|
+
raw = raw if isinstance(raw, dict) else {}
|
|
384
|
+
|
|
385
|
+
def count(value: Any) -> int:
|
|
386
|
+
return value if isinstance(value, int) and not isinstance(value, bool) and 0 <= value <= _MAX_BATCH_PAPERS else 0
|
|
387
|
+
|
|
388
|
+
later: dict[str, Any] = {kind: count(raw.get(kind)) for kind in LATER_KINDS}
|
|
389
|
+
at = raw.get("blocked_at")
|
|
390
|
+
if later["blocked"] and isinstance(at, (int, float)) and not isinstance(at, bool) and at > 0:
|
|
391
|
+
later["blocked_at"] = float(at)
|
|
392
|
+
# Each kind's papers by DOI (user, 2026-11-24: the window's 重试 list names them; 剩余 lists the others), as many as
|
|
393
|
+
# it counts at most; none from a caller that does not send them.
|
|
394
|
+
papers = raw.get("papers")
|
|
395
|
+
if isinstance(papers, dict):
|
|
396
|
+
later["papers"] = {kind: [doi for doi in papers.get(kind) if isinstance(doi, str) and 0 < len(doi) <= 300][:later[kind]]
|
|
397
|
+
for kind in LATER_KINDS if isinstance(papers.get(kind), list)}
|
|
398
|
+
return later
|
|
399
|
+
|
|
400
|
+
|
|
368
401
|
def sync_batch(batch_id: str, total: int, done: int, succeeded: int, failed: int, *,
|
|
369
402
|
current: str = "", finished: bool = False, results: Any = None,
|
|
370
403
|
phase: str = "", channel: str = "", lanes: str = "", held: Any = None,
|
|
371
|
-
held_wait: bool = False) -> bool:
|
|
404
|
+
held_wait: bool = False, later: Any = None, switch_to: str = "") -> bool:
|
|
372
405
|
"""Record batch totals for items finished without the backend, or the batch end.
|
|
373
406
|
|
|
374
407
|
``results`` (the batch end only) is the caller's summary of every item,
|
|
@@ -382,7 +415,10 @@ def sync_batch(batch_id: str, total: int, done: int, succeeded: int, failed: int
|
|
|
382
415
|
stage and prompts (``_adopt_batch``). ``held``: the publishers the caller holds
|
|
383
416
|
(``_held``), each with a button to go on with them; an empty list clears them.
|
|
384
417
|
``held_wait``: nothing else is left and the batch waits for the user to go on with
|
|
385
|
-
them or end it (each report says it again; any other report, or a download, ends it).
|
|
418
|
+
them or end it (each report says it again; any other report, or a download, ends it).
|
|
419
|
+
``later``: the papers the caller holds for a later try (``_later``), kept until the next
|
|
420
|
+
report that says them; dropped at the batch end. ``switch_to``: the school the caller now
|
|
421
|
+
tries its papers without access with, which the card names for a moment (``switch_note``)."""
|
|
386
422
|
ctx = BatchContext.from_args(batch_id, max(1, min(done, total)), total, done, succeeded, failed)
|
|
387
423
|
if ctx is None or done > total:
|
|
388
424
|
return False
|
|
@@ -391,12 +427,15 @@ def sync_batch(batch_id: str, total: int, done: int, succeeded: int, failed: int
|
|
|
391
427
|
if finished and previous is None and (done == 0 or summary is not None):
|
|
392
428
|
return False
|
|
393
429
|
phase, channel, lanes = _short_line(phase), _short_line(channel), _short_line(lanes)
|
|
430
|
+
school = _short_line(switch_to, 40)
|
|
394
431
|
adopted = _adopt_batch(ctx.batch_id, total, (done, succeeded, failed),
|
|
395
432
|
beside_download=bool(lanes) and not finished,
|
|
396
433
|
**({"current": current} if current else {}),
|
|
397
434
|
**({"lanes": lanes} if lanes or finished else {}),
|
|
398
435
|
**({"held": [] if finished else _held(held)} if held is not None or finished else {}),
|
|
399
436
|
held_wait=bool(held_wait) and not finished,
|
|
437
|
+
**({"later": {} if finished else _later(later)} if later is not None or finished else {}),
|
|
438
|
+
**({"switch_note": {"school": school, "at": time.time()}} if school and not finished else {}),
|
|
400
439
|
stage="saved_pending_verification" if finished else "starting",
|
|
401
440
|
channel="" if finished else channel,
|
|
402
441
|
phase=(f"批量下载结束:成功 {succeeded},失败 {failed}" if finished
|
|
@@ -430,7 +469,17 @@ def _short_line(value: Any, limit: int = 80) -> str:
|
|
|
430
469
|
return " ".join(value.split())[:limit]
|
|
431
470
|
|
|
432
471
|
|
|
433
|
-
|
|
472
|
+
# The five failure classes (PaperSearch's failureClass.ts; docs/contracts/failure-reasons.zh.md), and the eight before
|
|
473
|
+
# 2026-11-22 as they map to them (a PaperSearch older than this backend may still send those).
|
|
474
|
+
FAILURE_CLASSES = ("no_access", "user_side", "external", "unsupported", "unexplained")
|
|
475
|
+
_OLD_CLASSES = {"school_side": "external", "publisher_or_network": "external", "article_or_site": "external",
|
|
476
|
+
"adaptation": "unsupported"}
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def _failure_class(value: Any) -> str:
|
|
480
|
+
value = _OLD_CLASSES.get(value, value) if isinstance(value, str) else value
|
|
481
|
+
return value if value in FAILURE_CLASSES else "unexplained"
|
|
482
|
+
|
|
434
483
|
_RESULT_CONTENTS = ("main", "supplements", "both", "markdown")
|
|
435
484
|
# A bound against malformed input only: a batch has no limit since 7a38a068 (user, 2026-11-17). Left at its old 1000,
|
|
436
485
|
# a batch's papers after the 1000th were left out of the lists (user, 2026-11-21: 失败 1 on the card, the list empty,
|
|
@@ -496,7 +545,7 @@ def _batch_results(raw: Any) -> dict[str, Any] | None:
|
|
|
496
545
|
if not isinstance(item, dict) or not text(item.get("reason")):
|
|
497
546
|
continue
|
|
498
547
|
summary[key].append({
|
|
499
|
-
"cls":
|
|
548
|
+
"cls": _failure_class(item.get("cls")),
|
|
500
549
|
**{field: text(item.get(field)) for field in ("reason", "title", "journal", "doi", "note")},
|
|
501
550
|
# A site not yet supported (its note says where it fell short).
|
|
502
551
|
**({"unverified": True} if item.get("unverified") is True else {}),
|
|
@@ -544,18 +593,17 @@ def _paper(raw: Any) -> dict[str, Any] | None:
|
|
|
544
593
|
if isinstance(files, int) and not isinstance(files, bool) and 0 <= files <= 100_000:
|
|
545
594
|
paper["supplements_saved"] = files
|
|
546
595
|
if raw.get("supplement_reason"): # saved, but not every supplementary file
|
|
547
|
-
paper.update(supplement_cls=
|
|
548
|
-
|
|
596
|
+
paper.update(supplement_cls=_failure_class(raw.get("supplement_cls")),
|
|
597
|
+
supplement_reason=_display_text(raw.get("supplement_reason")))
|
|
549
598
|
if raw.get("markdown_reason"): # saved, without the Markdown asked for
|
|
550
|
-
paper.update(markdown_cls=
|
|
551
|
-
|
|
599
|
+
paper.update(markdown_cls=_failure_class(raw.get("markdown_cls")),
|
|
600
|
+
markdown_reason=_display_text(raw.get("markdown_reason")))
|
|
552
601
|
# Saved with a Markdown its checks found short, from a registered site's page (user, 2026-11-17).
|
|
553
602
|
if _display_text(raw.get("markdown_doubt_reason")):
|
|
554
603
|
paper.update(markdown_doubt_reason=_display_text(raw.get("markdown_doubt_reason")),
|
|
555
604
|
markdown_doubt_note=_display_text(raw.get("markdown_doubt_note")))
|
|
556
605
|
elif paper["state"] == "failed":
|
|
557
|
-
paper.update(cls=raw.get("cls")
|
|
558
|
-
reason=_display_text(raw.get("reason")))
|
|
606
|
+
paper.update(cls=_failure_class(raw.get("cls")), reason=_display_text(raw.get("reason")))
|
|
559
607
|
# Its page from a site not yet supported (user, 2026-11-16): the site, whether its Markdown
|
|
560
608
|
# was kept or the batch gave the site up, a note on what it lacked, the kept report.
|
|
561
609
|
host = raw.get("markdown_host")
|
|
@@ -678,6 +726,16 @@ def tracked_download(current: str, output_dir: Any = None, batch: BatchContext |
|
|
|
678
726
|
_STATE.pop("held_wait", None) # nor waiting for the user to go on with held publishers
|
|
679
727
|
update(content=content if content in ("main", "supplements", "both", "markdown") else "main",
|
|
680
728
|
markdown=bool(markdown), page_reading=False)
|
|
729
|
+
if batch is not None:
|
|
730
|
+
with _LOCK:
|
|
731
|
+
# What the batch was asked for, kept from its first article: its lists say what its failed papers did not
|
|
732
|
+
# get by it. ``content`` is the running article's (the card's label), and the batch's end asks for the
|
|
733
|
+
# Markdown alone of those short of figures: the failed list's heading said "Markdown 未生成" a while
|
|
734
|
+
# (Windows, 2026-11-24).
|
|
735
|
+
if _STATE and _STATE.get("batch_content_of") != batch.batch_id:
|
|
736
|
+
_STATE["batch_content"] = _STATE.get("content")
|
|
737
|
+
_STATE["batch_content_of"] = batch.batch_id
|
|
738
|
+
_write_state()
|
|
681
739
|
if output_dir:
|
|
682
740
|
set_output_dir(output_dir)
|
|
683
741
|
name_journal(current)
|
|
@@ -61,9 +61,10 @@ TERMINAL_STATUSES = frozenset({"done", "failed", "cancelled", "interrupted"})
|
|
|
61
61
|
MAX_REASON_ROWS = 5
|
|
62
62
|
OPEN_FAILURES_UP_TO = 3
|
|
63
63
|
MAX_LISTED_PAPERS = 200
|
|
64
|
-
CLASS_ORDER = ("no_access", "user_side", "
|
|
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,34 @@ 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
|
+
|
|
433
446
|
def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
434
447
|
"""Everything the capsule shows for one snapshot of the progress file.
|
|
435
448
|
|
|
@@ -451,7 +464,7 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
451
464
|
awaiting = bool(state.get("awaiting_next"))
|
|
452
465
|
# Publishers whose school login stopped working mid-batch, held by the caller:
|
|
453
466
|
# 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")),
|
|
467
|
+
held = [{"key": str(entry.get("key")), "name": str(entry.get("name") or entry.get("key")).removeprefix("site:"),
|
|
455
468
|
"count": int(entry.get("count") or 0)}
|
|
456
469
|
for entry in (state.get("held") or []) if running and isinstance(entry, dict) and entry.get("key")]
|
|
457
470
|
# Nothing else left: the batch waits for the user, which the collapsed capsule says
|
|
@@ -483,6 +496,10 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
483
496
|
# Before any publisher (the caller's open-access stretch), the channel stands in.
|
|
484
497
|
publisher = str(state.get("publisher") or "") or str(state.get("channel") or "")
|
|
485
498
|
journal = str(state.get("journal") or "")
|
|
499
|
+
# A site without rules of its own runs under "site:<domain>" (publishers/site.py), a name never shown: its journal
|
|
500
|
+
# names it, else its domain (user, 2026-11-24: "site:bristoluniversitypressdigital.com" on the capsule, often).
|
|
501
|
+
if publisher.startswith("site:"):
|
|
502
|
+
publisher = journal or publisher[len("site:"):]
|
|
486
503
|
current = str((attention[-1].get("current") if attention else "") or state.get("current") or "")
|
|
487
504
|
title = str(state.get("title") or "")
|
|
488
505
|
if held_wait:
|
|
@@ -567,7 +584,8 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
567
584
|
"ok": ok, "bad": bad, "left": max(0, total - done) if running and total else None,
|
|
568
585
|
"stopped": stopped,
|
|
569
586
|
"part": part, "publisher": publisher,
|
|
570
|
-
|
|
587
|
+
# A journal named as its publisher (Science, JAMA, BMJ, PNAS) once (user, 2026-11-23).
|
|
588
|
+
"where": " · ".join(v for v in (journal, "" if publisher.casefold() == journal.casefold() else publisher) if v),
|
|
571
589
|
"title": title, "current": current,
|
|
572
590
|
"run_id": str(state.get("run_id") or ""),
|
|
573
591
|
"step": step, "steps": list(steps), "line": line,
|
|
@@ -583,6 +601,8 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
583
601
|
and (not awaiting or bool(state.get("browser_pid") or state.get("browser_pids"))),
|
|
584
602
|
"stop_left": max(0, total - done - 1),
|
|
585
603
|
"held": held, "held_wait": held_wait,
|
|
604
|
+
"later": _later(state, max(0, total - done)) if running else None,
|
|
605
|
+
"switch_note": _switch_note(state, now) if running else "",
|
|
586
606
|
"folder": bool(state.get("output_dir")),
|
|
587
607
|
}
|
|
588
608
|
|
|
@@ -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/"
|