papersearch 0.7.1 → 0.7.2
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/dist/capabilities/download/batch/batch.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batch.js +12 -1
- package/dist/capabilities/download/batch/batch.js.map +1 -1
- package/dist/capabilities/download/batch/batchSummary.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batchSummary.js +16 -7
- package/dist/capabilities/download/batch/batchSummary.js.map +1 -1
- package/dist/capabilities/download/batch/journalKey.d.ts +12 -0
- package/dist/capabilities/download/batch/journalKey.d.ts.map +1 -0
- package/dist/capabilities/download/batch/journalKey.js +30 -0
- package/dist/capabilities/download/batch/journalKey.js.map +1 -0
- package/dist/capabilities/download/content/pdf/DownloadTier.d.ts +4 -0
- package/dist/capabilities/download/content/pdf/DownloadTier.d.ts.map +1 -1
- package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.d.ts.map +1 -1
- package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.js +2 -0
- package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.js.map +1 -1
- package/dist/capabilities/download/content/pdf/school.js +2 -0
- package/dist/capabilities/download/content/pdf/school.js.map +1 -1
- package/dist/capabilities/download/types.d.ts +4 -0
- package/dist/capabilities/download/types.d.ts.map +1 -1
- package/dist/cli.js +32 -9
- package/dist/cli.js.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.d.ts +4 -0
- package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.js +20 -1
- package/dist/infrastructure/school/SchoolMcpClient.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 +3 -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 +5 -0
- package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -1
- package/dist/infrastructure/school/types.d.ts +12 -0
- package/dist/infrastructure/school/types.d.ts.map +1 -1
- package/dist/management/pro/activate.d.ts +36 -0
- package/dist/management/pro/activate.d.ts.map +1 -0
- package/dist/management/pro/activate.js +122 -0
- package/dist/management/pro/activate.js.map +1 -0
- package/dist/management/pro/install.d.ts +15 -0
- package/dist/management/pro/install.d.ts.map +1 -1
- package/dist/management/pro/install.js +39 -12
- package/dist/management/pro/install.js.map +1 -1
- package/dist/management/reports/index.d.ts +6 -0
- package/dist/management/reports/index.d.ts.map +1 -1
- package/dist/management/reports/index.js +6 -0
- package/dist/management/reports/index.js.map +1 -1
- package/dist/management/school/autoUpdate.d.ts.map +1 -1
- package/dist/management/school/autoUpdate.js +1 -0
- 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 +1 -0
- package/dist/management/school/cliProgress.js.map +1 -1
- package/dist/management/school/settingsWindow.d.ts +1 -0
- package/dist/management/school/settingsWindow.d.ts.map +1 -1
- package/dist/management/school/settingsWindow.js +2 -0
- package/dist/management/school/settingsWindow.js.map +1 -1
- package/dist/management/updates/selfUpdate.d.ts +86 -0
- package/dist/management/updates/selfUpdate.d.ts.map +1 -0
- package/dist/management/updates/selfUpdate.js +194 -0
- package/dist/management/updates/selfUpdate.js.map +1 -0
- package/package.json +1 -1
- package/school/paper_search_school/adapters/annual_reviews/__init__.py +1 -0
- package/school/paper_search_school/adapters/ieee/__init__.py +1 -0
- package/school/paper_search_school/assets/capsule.html +927 -202
- package/school/paper_search_school/assets/capsule_en.json +290 -22
- package/school/paper_search_school/assets/capsule_fr.json +1331 -0
- package/school/paper_search_school/assets/capsule_ja.json +1331 -0
- package/school/paper_search_school/assets/capsule_ko.json +1331 -0
- package/school/paper_search_school/assets/capsule_zh-Hant.json +2462 -0
- package/school/paper_search_school/cli.py +15 -1
- package/school/paper_search_school/cold_start.py +70 -8
- package/school/paper_search_school/config.py +2 -0
- package/school/paper_search_school/download_diagnostics.py +4 -4
- package/school/paper_search_school/engine/batch_capture.py +35 -1
- package/school/paper_search_school/engine/batch_diagnostics.py +1 -1
- package/school/paper_search_school/engine/batch_institution.py +41 -0
- package/school/paper_search_school/engine/batch_login.py +65 -1
- package/school/paper_search_school/engine/batch_waits.py +22 -8
- package/school/paper_search_school/engine/bridge.py +11 -0
- package/school/paper_search_school/i18n.py +46 -22
- package/school/paper_search_school/orchestrator.py +60 -8
- package/school/paper_search_school/pro_status.py +54 -63
- package/school/paper_search_school/progress_capsule.py +180 -24
- package/school/paper_search_school/progress_reporter.py +51 -5
- package/school/paper_search_school/progress_view.py +3 -2
- package/school/paper_search_school/school_login.py +18 -4
- package/school/paper_search_school/school_switch.py +102 -0
- package/school/paper_search_school/school_test.py +335 -0
- package/school/paper_search_school/server.py +16 -0
- package/school/paper_search_school/updates.py +222 -0
- package/school/paper_search_school/user_settings.py +8 -3
- package/skills/paper-search/SKILL.md +1 -1
- package/skills/paper-search/references/cli-contract.md +1 -1
- package/skills/paper-search/references/school-setup.md +1 -1
|
@@ -45,9 +45,13 @@ def download_institutional(
|
|
|
45
45
|
login_wait: int | None = None,
|
|
46
46
|
fulltext: bool | str | None = None,
|
|
47
47
|
school: str | None = None,
|
|
48
|
+
fresh: bool = False,
|
|
48
49
|
) -> dict[str, Any]:
|
|
49
50
|
"""Download one DOI through institutional access only.
|
|
50
51
|
|
|
52
|
+
``fresh`` (the settings' 测试登录, school_test.py): neither from the cache nor into it: the download itself is
|
|
53
|
+
what is tested.
|
|
54
|
+
|
|
51
55
|
``login_only`` (``login``): the download's own steps up to the article's
|
|
52
56
|
access, then stop: no PDF, nothing cached. ``login_wait``: seconds to wait
|
|
53
57
|
on the school's login page instead of the setting.
|
|
@@ -97,6 +101,8 @@ def download_institutional(
|
|
|
97
101
|
extra["login_wait"] = login_wait
|
|
98
102
|
if school and school.strip():
|
|
99
103
|
extra["school"] = school.strip()
|
|
104
|
+
if fresh:
|
|
105
|
+
extra["fresh"] = True
|
|
100
106
|
return _download_impl(doi, output_dir, **extra)
|
|
101
107
|
finally:
|
|
102
108
|
with _INFLIGHT_LOCK:
|
|
@@ -107,7 +113,7 @@ def _download_impl(doi: str, output_dir: str | Path | None, *,
|
|
|
107
113
|
supplements: str | None = None, user_wait: str | None = None,
|
|
108
114
|
diagnostics_dir: str | None = None, title: str | None = None,
|
|
109
115
|
login_only: bool = False, login_wait: int | None = None,
|
|
110
|
-
fulltext: str | None = None, school: str | None = None) -> dict[str, Any]:
|
|
116
|
+
fulltext: str | None = None, school: str | None = None, fresh: bool = False) -> dict[str, Any]:
|
|
111
117
|
config = load_config()
|
|
112
118
|
if school:
|
|
113
119
|
# Another saved school for this download alone, as the user asked; the config's own
|
|
@@ -146,7 +152,7 @@ def _download_impl(doi: str, output_dir: str | Path | None, *,
|
|
|
146
152
|
config["diagnostics_dir"] = str(Path(diagnostics_dir).resolve())
|
|
147
153
|
output_path = target_dir / f"{safe_filename(doi)}.pdf"
|
|
148
154
|
|
|
149
|
-
cached = None if login_only else cache_get(doi, config)
|
|
155
|
+
cached = None if login_only or fresh else cache_get(doi, config)
|
|
150
156
|
if cached and cached.get("success"):
|
|
151
157
|
cached_file = Path(str(cached.get("file") or ""))
|
|
152
158
|
if cached_file.exists() and is_pdf_file(cached_file):
|
|
@@ -161,12 +167,56 @@ def _download_impl(doi: str, output_dir: str | Path | None, *,
|
|
|
161
167
|
return cached
|
|
162
168
|
|
|
163
169
|
log.info(f"paper-search-school - {doi}")
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
+
# Another school than the one the browser last signed in with: that sign-in forgotten first; a test
|
|
171
|
+
# (``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 school_switch
|
|
174
|
+
from .schools import saved as saved_schools
|
|
175
|
+
|
|
176
|
+
# 没权限时换下一所学校 (school_switch.py): the schools to try in turn, its journal's school of this task first.
|
|
177
|
+
# One alone: the switch off, a school named for this download, the test of one, a sign-in only.
|
|
178
|
+
turns = (school_switch.order_for(config, doi) if school_switch.enabled(config) and not school and not fresh
|
|
179
|
+
and not login_only else [])
|
|
180
|
+
if turns and not saved_schools.is_current(config, turns[0]):
|
|
181
|
+
saved_schools.apply(config, turns[0])
|
|
182
|
+
turn = 0
|
|
183
|
+
while True:
|
|
184
|
+
signed = before_sign_in(config, always=fresh)
|
|
185
|
+
if signed == "cleared":
|
|
186
|
+
log.info(" [Institutional] the browser's sign-in with another school forgotten")
|
|
187
|
+
elif signed == "busy" and fresh:
|
|
188
|
+
return fail(doi, "the download browser is open", error_type="browser_busy", action="close_browser")
|
|
189
|
+
|
|
190
|
+
try:
|
|
191
|
+
result = try_institutional(doi, output_path, config)
|
|
192
|
+
except Exception as exc:
|
|
193
|
+
log.info(f" [Institutional] route exception: {type(exc).__name__}")
|
|
194
|
+
return fail(doi, "institutional route raised", error_type="source_exception", action="review_logs")
|
|
195
|
+
if turn + 1 >= len(turns) or not school_switch.no_access(result):
|
|
196
|
+
break
|
|
197
|
+
# Signed in, no access: the next school, its sign-in after this one's is forgotten (the batch's browser closed
|
|
198
|
+
# first to let go of it; one that will not let go ends the turns: the next would try this school's session).
|
|
199
|
+
turn += 1
|
|
200
|
+
following = turns[turn]
|
|
201
|
+
log.info(f" [Institutional] no access with {school_switch.name(turns[turn - 1])}; next: {school_switch.name(following)}")
|
|
202
|
+
from . import progress_reporter
|
|
203
|
+
from .browser.batch_session import active_batch
|
|
204
|
+
|
|
205
|
+
progress_reporter.update(stage="switching_school", phase=f"没权限,换{school_switch.name(following)}")
|
|
206
|
+
batch = active_batch.get()
|
|
207
|
+
if batch is not None:
|
|
208
|
+
batch.close()
|
|
209
|
+
saved_schools.apply(config, following)
|
|
210
|
+
if before_sign_in(config) == "busy":
|
|
211
|
+
log.info(" [Institutional] the browser kept the last school's sign-in; no other school tried")
|
|
212
|
+
turn -= 1
|
|
213
|
+
break
|
|
214
|
+
if len(turns) > 1 and result and result.get("success"):
|
|
215
|
+
school_switch.remember(doi, str(config.get("idp_entity_id") or "").strip())
|
|
216
|
+
if turn or not saved_schools.is_current(load_config(), turns[turn]):
|
|
217
|
+
result["school"] = school_switch.name(turns[turn]) # not the default school's: the results say whose
|
|
218
|
+
elif turns and turn and school_switch.no_access(result):
|
|
219
|
+
result["schools_tried"] = turn + 1 # the lists say "N 所学校都没有权限"
|
|
170
220
|
# An article that re-checked a blocked journal's site: open again unless blocked again.
|
|
171
221
|
from . import blocked_journals
|
|
172
222
|
blocked_journals.recheck_ended(doi, blocked=bool(result) and result.get("error_type") == "access_blocked")
|
|
@@ -193,5 +243,7 @@ def _download_impl(doi: str, output_dir: str | Path | None, *,
|
|
|
193
243
|
result.setdefault("doi", doi)
|
|
194
244
|
result["file"] = str(file_path)
|
|
195
245
|
result.setdefault("size_kb", round(file_path.stat().st_size / 1024, 1))
|
|
246
|
+
if fresh:
|
|
247
|
+
return result
|
|
196
248
|
cache_set(doi, result, config)
|
|
197
249
|
return result
|
|
@@ -6,6 +6,7 @@ from __future__ import annotations
|
|
|
6
6
|
|
|
7
7
|
import json
|
|
8
8
|
import os
|
|
9
|
+
import re
|
|
9
10
|
from pathlib import Path
|
|
10
11
|
from typing import Any, Mapping
|
|
11
12
|
from urllib.parse import quote
|
|
@@ -47,7 +48,7 @@ def status(env: Mapping[str, str] | None = None) -> dict[str, Any]:
|
|
|
47
48
|
command line counts) and whether Pro is free now (pro/access.json, which Pro keeps)."""
|
|
48
49
|
path = entry(env)
|
|
49
50
|
if not path.is_file():
|
|
50
|
-
return {"installed": False, "version": ""}
|
|
51
|
+
return {"installed": False, "version": "", "activation": activation(env)}
|
|
51
52
|
manifest = _read(path.parent / "pro.json")
|
|
52
53
|
sites = manifest.get("sites")
|
|
53
54
|
stats = _read(data_home(env) / "pro" / "stats.json")
|
|
@@ -62,9 +63,28 @@ def status(env: Mapping[str, str] | None = None) -> dict[str, Any]:
|
|
|
62
63
|
"complete": min(converted, _count(stats.get("complete"))),
|
|
63
64
|
"access": {"mode": access.get("mode") if access.get("mode") in ("free", "key") else "free",
|
|
64
65
|
"until": _day(until)},
|
|
66
|
+
"activation": activation(env),
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
|
|
70
|
+
_DAY = re.compile(r"^\d{4}-\d{2}-\d{2}$")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def activation(env: Mapping[str, str] | None = None) -> dict[str, str]:
|
|
74
|
+
"""Whether this computer is activated (user, 2026-11-21), from ``pro/activation.json``, which
|
|
75
|
+
``paper-search pro activate`` keeps (src/management/pro/activate.ts): none, active or expired,
|
|
76
|
+
the code's last four characters and the day it ends. The code itself is not handed on."""
|
|
77
|
+
record = _read(data_home(env) / "pro" / "activation.json")
|
|
78
|
+
code = record.get("code")
|
|
79
|
+
if not isinstance(code, str) or not code:
|
|
80
|
+
return {"state": "none", "tail": "", "until": ""}
|
|
81
|
+
until = record.get("until") if isinstance(record.get("until"), str) and _DAY.match(record["until"]) else ""
|
|
82
|
+
import time
|
|
83
|
+
|
|
84
|
+
expired = bool(until) and until < time.strftime("%Y-%m-%d", time.localtime())
|
|
85
|
+
return {"state": "expired" if expired else "active", "tail": code[-4:], "until": until}
|
|
86
|
+
|
|
87
|
+
|
|
68
88
|
def _day(ms: Any) -> str:
|
|
69
89
|
"""A free setting's end ("2027-03-01"), from Pro's milliseconds; "" for none."""
|
|
70
90
|
import time
|
|
@@ -74,64 +94,11 @@ def _day(ms: Any) -> str:
|
|
|
74
94
|
return time.strftime("%Y-%m-%d", time.localtime(ms / 1000))
|
|
75
95
|
|
|
76
96
|
|
|
77
|
-
class ProCheck:
|
|
78
|
-
"""The Markdown page's 检查更新: ``paper-search pro check`` in the background (user, 2026-11-19);
|
|
79
|
-
the page asks for ``state()`` until it is done: the newest version and whether it is newer."""
|
|
80
|
-
|
|
81
|
-
def __init__(self, command_of=None, run=None):
|
|
82
|
-
import threading
|
|
83
|
-
|
|
84
|
-
from .api_keys import paper_search_command
|
|
85
|
-
|
|
86
|
-
self._command_of = command_of or paper_search_command
|
|
87
|
-
self._run_command = run
|
|
88
|
-
self._lock = threading.Lock()
|
|
89
|
-
self._state: dict[str, Any] = {"state": "idle"}
|
|
90
|
-
|
|
91
|
-
def state(self) -> dict[str, Any]:
|
|
92
|
-
with self._lock:
|
|
93
|
-
return dict(self._state)
|
|
94
|
-
|
|
95
|
-
def start(self) -> dict[str, Any]:
|
|
96
|
-
import threading
|
|
97
|
-
|
|
98
|
-
with self._lock:
|
|
99
|
-
if self._state.get("state") == "running":
|
|
100
|
-
return dict(self._state)
|
|
101
|
-
self._state = {"state": "running"}
|
|
102
|
-
threading.Thread(target=self._check, name="pro-check", daemon=True).start()
|
|
103
|
-
return {"state": "running"}
|
|
104
|
-
|
|
105
|
-
def _check(self) -> None:
|
|
106
|
-
import subprocess
|
|
107
|
-
|
|
108
|
-
command = self._command_of()
|
|
109
|
-
answer: dict[str, Any] = {}
|
|
110
|
-
if command is None:
|
|
111
|
-
answer = {"ok": False, "message": "找不到 paper-search 命令"}
|
|
112
|
-
else:
|
|
113
|
-
env = {**os.environ, "PAPER_SEARCH_SKILL_AUTO_UPDATE": "false", "PAPER_SEARCH_UPDATE_NOTIFY": "false"}
|
|
114
|
-
try:
|
|
115
|
-
run = self._run_command or (lambda argv: subprocess.run(
|
|
116
|
-
argv, capture_output=True, encoding="utf-8", errors="replace", env=env, timeout=60).stdout)
|
|
117
|
-
lines = [line for line in str(run([*command, "pro", "check"]) or "").splitlines() if line.strip()]
|
|
118
|
-
answer = json.loads(lines[-1]) if lines else {}
|
|
119
|
-
except Exception:
|
|
120
|
-
answer = {}
|
|
121
|
-
with self._lock:
|
|
122
|
-
if isinstance(answer, dict) and answer.get("ok") is True:
|
|
123
|
-
self._state = {"state": "done", "latest": str(answer.get("latest") or ""),
|
|
124
|
-
"update": answer.get("update") is True}
|
|
125
|
-
else:
|
|
126
|
-
message = answer.get("message") if isinstance(answer, dict) else ""
|
|
127
|
-
self._state = {"state": "failed", "message": str(message or "检查更新出错")}
|
|
128
|
-
|
|
129
|
-
|
|
130
97
|
class ProInstall:
|
|
131
98
|
"""The settings window's 安装: ``paper-search pro install --progress`` in the background, its
|
|
132
99
|
progress lines read as they come; the page asks for ``state()`` until it is done or failed."""
|
|
133
100
|
|
|
134
|
-
def __init__(self, command_of=None, popen=None):
|
|
101
|
+
def __init__(self, command_of=None, popen=None, run=None):
|
|
135
102
|
import subprocess
|
|
136
103
|
import threading
|
|
137
104
|
|
|
@@ -139,6 +106,7 @@ class ProInstall:
|
|
|
139
106
|
|
|
140
107
|
self._command_of = command_of or paper_search_command
|
|
141
108
|
self._popen = popen or subprocess.Popen
|
|
109
|
+
self._run_command = run or subprocess.run
|
|
142
110
|
self._lock = threading.Lock()
|
|
143
111
|
self._state: dict[str, Any] = {"state": "idle"}
|
|
144
112
|
|
|
@@ -150,25 +118,47 @@ class ProInstall:
|
|
|
150
118
|
with self._lock:
|
|
151
119
|
self._state = state
|
|
152
120
|
|
|
153
|
-
def start(self) -> dict[str, Any]:
|
|
121
|
+
def start(self, code: str | None = None) -> dict[str, Any]:
|
|
122
|
+
"""安装, or with the code typed on Pro's page 激活并安装: ``paper-search pro activate`` first
|
|
123
|
+
(user, 2026-11-21), the code handed on standard input; the install only once it is active."""
|
|
154
124
|
import threading
|
|
155
125
|
|
|
156
126
|
with self._lock:
|
|
157
127
|
if self._state.get("state") == "running":
|
|
158
128
|
return dict(self._state)
|
|
159
|
-
|
|
160
|
-
|
|
129
|
+
activating = code is not None
|
|
130
|
+
self._state = started = ({"state": "running", "step": "activate"} if activating
|
|
131
|
+
else {"state": "running", "step": "install", "done": 0, "total": 0})
|
|
132
|
+
threading.Thread(target=self._run, args=(code,), name="pro-install", daemon=True).start()
|
|
161
133
|
return dict(started)
|
|
162
134
|
|
|
163
|
-
def
|
|
135
|
+
def _activate(self, command: list[str], env: dict[str, str], code: str) -> bool:
|
|
136
|
+
try:
|
|
137
|
+
run = self._run_command([*command, "pro", "activate"], input=code, capture_output=True, encoding="utf-8",
|
|
138
|
+
errors="replace", env=env, timeout=60)
|
|
139
|
+
lines = [line for line in (run.stdout or "").splitlines() if line.strip()]
|
|
140
|
+
answer = json.loads(lines[-1]) if lines else {}
|
|
141
|
+
except Exception:
|
|
142
|
+
answer = {}
|
|
143
|
+
if isinstance(answer, dict) and answer.get("ok") is True:
|
|
144
|
+
return True
|
|
145
|
+
message = answer.get("message") or answer.get("error") if isinstance(answer, dict) else ""
|
|
146
|
+
self._set(state="failed", step="activate", message=str(message or "激活出错"))
|
|
147
|
+
return False
|
|
148
|
+
|
|
149
|
+
def _run(self, code: str | None = None) -> None:
|
|
164
150
|
import subprocess
|
|
165
151
|
|
|
166
152
|
command = self._command_of()
|
|
167
153
|
if command is None:
|
|
168
|
-
self._set(state="failed", message="找不到 paper-search 命令")
|
|
154
|
+
self._set(state="failed", step="activate" if code is not None else "install", message="找不到 paper-search 命令")
|
|
169
155
|
return
|
|
170
156
|
# An install must not also update the Skill or check for a new version.
|
|
171
157
|
env = {**os.environ, "PAPER_SEARCH_SKILL_AUTO_UPDATE": "false", "PAPER_SEARCH_UPDATE_NOTIFY": "false"}
|
|
158
|
+
if code is not None:
|
|
159
|
+
if not self._activate(command, env, code):
|
|
160
|
+
return
|
|
161
|
+
self._set(state="running", step="install", done=0, total=0)
|
|
172
162
|
last: dict[str, Any] = {}
|
|
173
163
|
try:
|
|
174
164
|
process = self._popen([*command, "pro", "install", "--progress"], stdout=subprocess.PIPE,
|
|
@@ -179,14 +169,15 @@ class ProInstall:
|
|
|
179
169
|
except ValueError:
|
|
180
170
|
continue
|
|
181
171
|
if isinstance(message, dict) and message.get("event") == "progress":
|
|
182
|
-
self._set(state="running",
|
|
172
|
+
self._set(state="running", step="install", done=int(message.get("done") or 0),
|
|
173
|
+
total=int(message.get("total") or 0))
|
|
183
174
|
elif isinstance(message, dict):
|
|
184
175
|
last = message
|
|
185
176
|
process.wait(timeout=60)
|
|
186
177
|
except Exception:
|
|
187
|
-
self._set(state="failed", message="安装出错")
|
|
178
|
+
self._set(state="failed", step="install", message="安装出错")
|
|
188
179
|
return
|
|
189
180
|
if last.get("ok") is True:
|
|
190
181
|
self._set(state="done", version=str(last.get("version") or ""))
|
|
191
182
|
else:
|
|
192
|
-
self._set(state="failed", message=str(last.get("message") or last.get("error") or "安装出错"))
|
|
183
|
+
self._set(state="failed", step="install", message=str(last.get("message") or last.get("error") or "安装出错"))
|
|
@@ -38,9 +38,16 @@ ASSETS = Path(__file__).with_name("assets")
|
|
|
38
38
|
PAGE = ASSETS / "capsule.html"
|
|
39
39
|
|
|
40
40
|
|
|
41
|
+
#: Where each language's table goes in the page.
|
|
42
|
+
_TABLE_MARKS = {"en": "CAPSULE_EN", "zh-Hant": "CAPSULE_ZH_HANT", "ja": "CAPSULE_JA", "ko": "CAPSULE_KO", "fr": "CAPSULE_FR"}
|
|
43
|
+
|
|
44
|
+
|
|
41
45
|
def page_html() -> str:
|
|
42
|
-
"""The page with its
|
|
43
|
-
|
|
46
|
+
"""The page with its tables in it, one per language (the window loads it as one string)."""
|
|
47
|
+
page = PAGE.read_text(encoding="utf-8")
|
|
48
|
+
for code, mark in _TABLE_MARKS.items():
|
|
49
|
+
page = page.replace(f"/*{mark}*/null", i18n.TABLES[code].read_text(encoding="utf-8"))
|
|
50
|
+
return page
|
|
44
51
|
# PaperSearch's icon (assets/icon.svg) for the Dock.
|
|
45
52
|
ICON = ASSETS / "icon-512.png"
|
|
46
53
|
# The first, collapsed frame; the page then reports the size it needs.
|
|
@@ -144,6 +151,10 @@ class Notifier:
|
|
|
144
151
|
threading.Thread(target=self._send, args=("PaperSearch", message, state), daemon=True).start()
|
|
145
152
|
|
|
146
153
|
|
|
154
|
+
#: How many schools 添加学校 lists at most (a country's name finds all of its).
|
|
155
|
+
FOUND_SHOWN = 50
|
|
156
|
+
|
|
157
|
+
|
|
147
158
|
class Api:
|
|
148
159
|
"""What the page calls (``window.pywebview.api``). Every method returns
|
|
149
160
|
plain values and never raises into the page."""
|
|
@@ -420,7 +431,7 @@ class Api:
|
|
|
420
431
|
def set_language(self, lang: str) -> dict[str, Any]:
|
|
421
432
|
"""The language switch saves at once and the page follows it."""
|
|
422
433
|
if lang not in i18n.LANGUAGES:
|
|
423
|
-
return {"ok": False, "error": "
|
|
434
|
+
return {"ok": False, "error": "不支持这种语言"}
|
|
424
435
|
try:
|
|
425
436
|
user_settings.set_language(lang)
|
|
426
437
|
except (OSError, ValueError) as exc:
|
|
@@ -606,7 +617,9 @@ class Api:
|
|
|
606
617
|
"status": school_login.school_status(entity_id, pro) if pro is not None else ""})
|
|
607
618
|
listed.sort(key=lambda school: not school["current"])
|
|
608
619
|
current = next((school for school in listed if school["current"]), {})
|
|
609
|
-
|
|
620
|
+
from . import school_switch
|
|
621
|
+
|
|
622
|
+
return {"ok": True, "pro": pro is not None, "schools": listed, "switch": school_switch.enabled(config),
|
|
610
623
|
"counts": school_login.school_counts(pro) if pro is not None else {},
|
|
611
624
|
"school": current.get("name", ""), "entity": bool(current.get("entity")), "saved": bool(current.get("saved")),
|
|
612
625
|
"username": current.get("username", ""), "enabled": bool(current.get("enabled")),
|
|
@@ -675,6 +688,82 @@ class Api:
|
|
|
675
688
|
return {"ok": False, "error": f"保存失败:{type(exc).__name__}"}
|
|
676
689
|
return self.school_login_state()
|
|
677
690
|
|
|
691
|
+
# 测试登录 (user, 2026-11-21; school_test.py): a saved school's account tried on an article, as a download goes.
|
|
692
|
+
def school_test_article(self, key: str = "") -> dict[str, Any]:
|
|
693
|
+
"""The article this school's test opens: {ok, doi} ("" while the user has set none)."""
|
|
694
|
+
if not pro_features():
|
|
695
|
+
return {"ok": False, "error": "这个版本没有自动登录"}
|
|
696
|
+
from .config import load_config
|
|
697
|
+
from .school_test import article
|
|
698
|
+
|
|
699
|
+
entity_id = self._login_school(load_config(), key)
|
|
700
|
+
return {"ok": True, **article(entity_id)} if entity_id else {"ok": False, "error": "这所学校还没有添加"}
|
|
701
|
+
|
|
702
|
+
def set_school_test_article(self, key: str = "", text: str = "") -> dict[str, Any]:
|
|
703
|
+
"""The article set by its DOI or its page's address (user, 2026-11-21: set by them, none for them)."""
|
|
704
|
+
if not pro_features():
|
|
705
|
+
return {"ok": False, "error": "这个版本没有自动登录"}
|
|
706
|
+
try:
|
|
707
|
+
from .config import load_config
|
|
708
|
+
from .school_test import set_article
|
|
709
|
+
|
|
710
|
+
entity_id = self._login_school(load_config(), key)
|
|
711
|
+
return set_article(entity_id, str(text or "")) if entity_id else {"ok": False, "error": "这所学校还没有添加"}
|
|
712
|
+
except Exception as exc:
|
|
713
|
+
return {"ok": False, "error": f"保存失败:{type(exc).__name__}"}
|
|
714
|
+
|
|
715
|
+
def start_school_test(self, key: str = "", doi: str = "") -> dict[str, Any]:
|
|
716
|
+
"""Starts the test of a saved school whose account is saved, on ``doi``; or says why not."""
|
|
717
|
+
if not pro_features():
|
|
718
|
+
return {"state": "idle", "error": "这个版本没有自动登录"}
|
|
719
|
+
try:
|
|
720
|
+
from . import school_login
|
|
721
|
+
from .config import load_config
|
|
722
|
+
|
|
723
|
+
config = load_config()
|
|
724
|
+
entity_id = self._login_school(config, key)
|
|
725
|
+
if not entity_id:
|
|
726
|
+
return {"state": "idle", "error": "这所学校还没有添加"}
|
|
727
|
+
if not school_login.saved(config, entity_id):
|
|
728
|
+
return {"state": "idle", "error": "先保存账号和密码,再测试"}
|
|
729
|
+
doi = str(doi or "").strip()
|
|
730
|
+
if not doi:
|
|
731
|
+
return {"state": "idle", "error": "先填测试文章"}
|
|
732
|
+
return self._school_test().start(entity_id, doi)
|
|
733
|
+
except Exception as exc:
|
|
734
|
+
return {"state": "idle", "error": f"测试没有开始:{type(exc).__name__}"}
|
|
735
|
+
|
|
736
|
+
def school_test_state(self) -> dict[str, Any]:
|
|
737
|
+
return self._school_test().state()
|
|
738
|
+
|
|
739
|
+
def stop_school_test(self) -> dict[str, Any]:
|
|
740
|
+
return self._school_test().stop()
|
|
741
|
+
|
|
742
|
+
def forget_school_test(self) -> dict[str, Any]:
|
|
743
|
+
self._school_test().forget()
|
|
744
|
+
return self._school_test().state()
|
|
745
|
+
|
|
746
|
+
def _school_test(self):
|
|
747
|
+
from .school_test import SchoolTest
|
|
748
|
+
|
|
749
|
+
test = getattr(self, "_test", None)
|
|
750
|
+
if test is None:
|
|
751
|
+
test = self._test = SchoolTest()
|
|
752
|
+
return test
|
|
753
|
+
|
|
754
|
+
def set_school_switch(self, on: bool = True) -> dict[str, Any]:
|
|
755
|
+
"""没权限时换下一所学校 on or off (school_switch.py); the page's state after it."""
|
|
756
|
+
if not pro_features():
|
|
757
|
+
return {"ok": False, "error": "这个版本没有自动登录"}
|
|
758
|
+
try:
|
|
759
|
+
from .config import update_config
|
|
760
|
+
from .school_switch import SETTING
|
|
761
|
+
|
|
762
|
+
update_config(SETTING, "true" if on else "false")
|
|
763
|
+
except Exception as exc:
|
|
764
|
+
return {"ok": False, "error": f"保存失败:{type(exc).__name__}"}
|
|
765
|
+
return self.school_login_state()
|
|
766
|
+
|
|
678
767
|
def clear_school_login(self, key: str = "") -> dict[str, Any]:
|
|
679
768
|
if not pro_features():
|
|
680
769
|
return {"ok": False, "error": "这个版本没有自动登录"}
|
|
@@ -710,16 +799,35 @@ class Api:
|
|
|
710
799
|
saved_schools.remember(config)
|
|
711
800
|
saved = {str(entry.get("idp_entity_id") or "").strip() for entry in saved_schools.saved(config)}
|
|
712
801
|
pro = school_login.module()
|
|
802
|
+
# 支持哪些学校's own search too (user, 2026-11-21: 台湾 found nothing here, Taiwan's schools there): Pro's
|
|
803
|
+
# list by any of its names (Wikidata's Chinese one among them), its country, province or state, in
|
|
804
|
+
# Chinese or English; each school's names in other languages for the page to show.
|
|
805
|
+
listed = [school for school in school_login.school_list(pro) if school["key"]] if pro is not None else []
|
|
806
|
+
known = {school["key"]: school for school in listed}
|
|
807
|
+
wanted = query.lower()
|
|
808
|
+
|
|
809
|
+
def said(school: dict[str, Any]) -> str:
|
|
810
|
+
places = [school["province"], school["area"], school["country"]]
|
|
811
|
+
return " ".join([school["name"], school["name_en"], *school["names"].values(), *places,
|
|
812
|
+
*(i18n.translate(place, "en") for place in places if place)]).lower()
|
|
813
|
+
|
|
713
814
|
results = [{"key": school.entity_id, "name": school.name, "name_en": school.name_en,
|
|
815
|
+
"names": known.get(school.entity_id, {}).get("names", {}),
|
|
714
816
|
"federation": school.summary()["federation"], "added": school.entity_id in saved,
|
|
715
817
|
"status": school_login.school_status(school.entity_id, pro) if pro is not None else ""}
|
|
716
818
|
for school in schools if school.entity_id]
|
|
819
|
+
taken = {result["key"] for result in results}
|
|
820
|
+
results += [{"key": school["key"], "name": school["name"], "name_en": school["name_en"], "names": school["names"],
|
|
821
|
+
"federation": school["country"], "added": school["key"] in saved, "status": school["status"]}
|
|
822
|
+
for school in listed if school["key"] not in taken and wanted in said(school)]
|
|
717
823
|
except Exception as exc:
|
|
718
824
|
return {"ok": False, "error": f"查找失败:{type(exc).__name__}"}
|
|
719
|
-
|
|
825
|
+
left = max(0, len(results) - FOUND_SHOWN)
|
|
826
|
+
note = (f"还有 {left} 所没列出,输入更完整的名称可以缩小范围" if left
|
|
827
|
+
else "" if results else "这所学校所在的学术联盟还不支持" if found.unsupported
|
|
720
828
|
else "学校名单暂时读不到,请稍后再试" if found.unavailable
|
|
721
829
|
else "没有找到这所学校:换成学校的正式中文名、英文名或网址试试")
|
|
722
|
-
return {"ok": True, "results": results, "note": note}
|
|
830
|
+
return {"ok": True, "results": results[:FOUND_SHOWN], "note": note}
|
|
723
831
|
|
|
724
832
|
def add_school(self, key: str = "") -> dict[str, Any]:
|
|
725
833
|
"""A school found by 添加学校 kept in the saved list, the default one unchanged (none yet: it)."""
|
|
@@ -804,28 +912,13 @@ class Api:
|
|
|
804
912
|
except Exception as exc:
|
|
805
913
|
return {"ok": False, "error": f"读取失败:{type(exc).__name__}"}
|
|
806
914
|
|
|
807
|
-
def install_pro(self) -> dict[str, Any]:
|
|
808
|
-
"""
|
|
809
|
-
return self._pro_installer().start()
|
|
915
|
+
def install_pro(self, code: str | None = None) -> dict[str, Any]:
|
|
916
|
+
"""Pro's 安装, or 激活并安装 with the code typed: starts it, or says how it goes (pro_install_state)."""
|
|
917
|
+
return self._pro_installer().start(None if code is None else str(code))
|
|
810
918
|
|
|
811
919
|
def pro_install_state(self) -> dict[str, Any]:
|
|
812
920
|
return self._pro_installer().state()
|
|
813
921
|
|
|
814
|
-
def check_pro(self) -> dict[str, Any]:
|
|
815
|
-
"""The Markdown page's 检查更新: starts it, or says how it goes (pro_check_state)."""
|
|
816
|
-
return self._pro_checker().start()
|
|
817
|
-
|
|
818
|
-
def pro_check_state(self) -> dict[str, Any]:
|
|
819
|
-
return self._pro_checker().state()
|
|
820
|
-
|
|
821
|
-
def _pro_checker(self):
|
|
822
|
-
from .pro_status import ProCheck
|
|
823
|
-
|
|
824
|
-
checker = getattr(self, "_pro_check", None)
|
|
825
|
-
if checker is None:
|
|
826
|
-
checker = self._pro_check = ProCheck()
|
|
827
|
-
return checker
|
|
828
|
-
|
|
829
922
|
def _pro_installer(self):
|
|
830
923
|
from .pro_status import ProInstall
|
|
831
924
|
|
|
@@ -834,6 +927,69 @@ class Api:
|
|
|
834
927
|
installer = self._pro_install = ProInstall()
|
|
835
928
|
return installer
|
|
836
929
|
|
|
930
|
+
# One version and one update (user, 2026-11-21; updates.py): the about page, the home page's foot, the card's dot.
|
|
931
|
+
def versions(self) -> dict[str, Any]:
|
|
932
|
+
"""The version this window runs and the one installed now (an update elsewhere: they differ)."""
|
|
933
|
+
from . import updates
|
|
934
|
+
|
|
935
|
+
return {"running": updates.RUNNING, "installed": updates.installed_version()}
|
|
936
|
+
|
|
937
|
+
def check_versions(self, again: bool = False) -> dict[str, Any]:
|
|
938
|
+
return self._version_check().start(bool(again))
|
|
939
|
+
|
|
940
|
+
def versions_state(self) -> dict[str, Any]:
|
|
941
|
+
return self._version_check().state()
|
|
942
|
+
|
|
943
|
+
def update_all(self) -> dict[str, Any]:
|
|
944
|
+
"""更新: what the last check found behind (PaperSearch, then its extension and Skills; Pro)."""
|
|
945
|
+
checked = self._version_check().state()
|
|
946
|
+
if checked.get("state") != "done":
|
|
947
|
+
return {"state": "idle", "error": "先检查更新"}
|
|
948
|
+
return self._updater().start(bool(checked.get("update")), bool(checked.get("pro_update")),
|
|
949
|
+
str(checked.get("latest") if checked.get("update") else ""))
|
|
950
|
+
|
|
951
|
+
def update_state(self) -> dict[str, Any]:
|
|
952
|
+
return self._updater().state()
|
|
953
|
+
|
|
954
|
+
def reopen_window(self, page: str = "about") -> dict[str, Any]:
|
|
955
|
+
"""The settings opened again with the PaperSearch installed now, once this window has closed."""
|
|
956
|
+
from . import updates
|
|
957
|
+
|
|
958
|
+
page = page if page in ("home", "about") else "about"
|
|
959
|
+
if not updates.reopen(page):
|
|
960
|
+
return {"ok": False, "message": "找不到 paper-search 命令,请关掉窗口后重新打开设置"}
|
|
961
|
+
threading.Timer(0.3, self.request_close).start()
|
|
962
|
+
return {"ok": True}
|
|
963
|
+
|
|
964
|
+
def open_release_notes(self) -> dict[str, Any]:
|
|
965
|
+
"""这次更新了什么: the release notes where the check found the new version."""
|
|
966
|
+
import webbrowser
|
|
967
|
+
|
|
968
|
+
url = str(self._version_check().state().get("notes") or "")
|
|
969
|
+
if not url.startswith("https://"):
|
|
970
|
+
return {"ok": False, "message": "没有更新说明"}
|
|
971
|
+
try:
|
|
972
|
+
opened = webbrowser.open(url)
|
|
973
|
+
except Exception as exc:
|
|
974
|
+
return {"ok": False, "message": f"打开失败:{type(exc).__name__}"}
|
|
975
|
+
return {"ok": True} if opened else {"ok": False, "message": "打开失败:没有找到默认浏览器"}
|
|
976
|
+
|
|
977
|
+
def _version_check(self):
|
|
978
|
+
from .updates import VersionCheck
|
|
979
|
+
|
|
980
|
+
check = getattr(self, "_versions", None)
|
|
981
|
+
if check is None:
|
|
982
|
+
check = self._versions = VersionCheck()
|
|
983
|
+
return check
|
|
984
|
+
|
|
985
|
+
def _updater(self):
|
|
986
|
+
from .updates import UpdateAll
|
|
987
|
+
|
|
988
|
+
updater = getattr(self, "_update_all", None)
|
|
989
|
+
if updater is None:
|
|
990
|
+
updater = self._update_all = UpdateAll()
|
|
991
|
+
return updater
|
|
992
|
+
|
|
837
993
|
def open_issue(self) -> dict[str, Any]:
|
|
838
994
|
"""GitHub's new-issue page for the Markdown, its title begun."""
|
|
839
995
|
import webbrowser
|