litloop 1.18.3__py3-none-any.whl
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.
- litloop/__init__.py +89 -0
- litloop/__main__.py +6 -0
- litloop/_source_hygiene.py +158 -0
- litloop/agents/__init__.py +13 -0
- litloop/agents/client.py +164 -0
- litloop/agents/runner.py +123 -0
- litloop/agents/system.py +54 -0
- litloop/agents/tools.py +142 -0
- litloop/app_server.py +8 -0
- litloop/browser/__init__.py +1 -0
- litloop/browser/backend.py +1009 -0
- litloop/browser/camofox_api.py +368 -0
- litloop/browser/chrome_copy.py +136 -0
- litloop/browser/cloakbrowser_compat.py +72 -0
- litloop/browser/cookies.py +347 -0
- litloop/browser/engine.py +965 -0
- litloop/browser/login.py +636 -0
- litloop/browser/pdf.py +263 -0
- litloop/browser/profile_health.py +167 -0
- litloop/browser/runtime.py +210 -0
- litloop/cache.py +104 -0
- litloop/citations/__init__.py +1 -0
- litloop/citations/bib_import.py +102 -0
- litloop/citations/bibtex_crossref.py +143 -0
- litloop/citations/formats.py +225 -0
- litloop/citations/paper_list.py +200 -0
- litloop/citations/session_export.py +94 -0
- litloop/cli/__init__.py +12 -0
- litloop/cli/_utils.py +267 -0
- litloop/cli/commands.py +1098 -0
- litloop/cli/doctor.py +141 -0
- litloop/cli/main.py +1173 -0
- litloop/cli/web.py +190 -0
- litloop/config.py +413 -0
- litloop/data/VARCON-LICENSE.txt +62 -0
- litloop/data/elements.tsv +119 -0
- litloop/data/institutional_identity_policy.json +165 -0
- litloop/data/publisher_access_catalog.json +969 -0
- litloop/data/publisher_carsi.json +105 -0
- litloop/data/spelling_search.tsv.gz +0 -0
- litloop/data/spelling_us.tsv.gz +0 -0
- litloop/data/webvpn.dat +0 -0
- litloop/data/webvpn.json +603 -0
- litloop/db.py +1922 -0
- litloop/deps.py +128 -0
- litloop/desktop/__init__.py +1 -0
- litloop/desktop/agent_runner.py +537 -0
- litloop/desktop/download_jobs.py +571 -0
- litloop/desktop/error_text.py +192 -0
- litloop/desktop/server.py +999 -0
- litloop/desktop/settings.py +552 -0
- litloop/desktop/translate.py +103 -0
- litloop/diagnostics.py +126 -0
- litloop/download/__init__.py +1 -0
- litloop/download/doi_check.py +44 -0
- litloop/download/fetcher.py +975 -0
- litloop/download/markdown.py +130 -0
- litloop/download/pdf.py +454 -0
- litloop/download/pipeline.py +1166 -0
- litloop/download/progress.py +312 -0
- litloop/download/rename.py +211 -0
- litloop/extractors/__init__.py +0 -0
- litloop/extractors/html_extractor.py +31 -0
- litloop/extractors/pdf_extractor.py +151 -0
- litloop/extractors/publisher_adapters/__init__.py +0 -0
- litloop/extractors/publisher_adapters/acs.py +167 -0
- litloop/extractors/publisher_adapters/elsevier.py +178 -0
- litloop/extractors/publisher_adapters/generic.py +191 -0
- litloop/extractors/publisher_adapters/nature.py +204 -0
- litloop/extractors/publisher_adapters/rsc.py +154 -0
- litloop/extractors/publisher_adapters/tandfonline.py +154 -0
- litloop/extractors/publisher_adapters/wiley.py +160 -0
- litloop/http_utils.py +57 -0
- litloop/identifiers.py +134 -0
- litloop/institutional/__init__.py +1 -0
- litloop/institutional/auth.py +576 -0
- litloop/institutional/carsi_login.py +569 -0
- litloop/institutional/config_adapter.py +63 -0
- litloop/institutional/proxy_check.py +98 -0
- litloop/institutional/remote_assist.py +274 -0
- litloop/institutional/schools.py +102 -0
- litloop/institutional/session_heal.py +73 -0
- litloop/institutional/session_store.py +105 -0
- litloop/log.py +47 -0
- litloop/models.py +269 -0
- litloop/network.py +417 -0
- litloop/optional.py +310 -0
- litloop/publishers/__init__.py +1 -0
- litloop/publishers/access.py +232 -0
- litloop/publishers/pdf_router.py +451 -0
- litloop/publishers/profiles.py +899 -0
- litloop/publishers/strategies/__init__.py +122 -0
- litloop/publishers/strategies/_core.py +2340 -0
- litloop/publishers/strategies/_elsevier_api.py +578 -0
- litloop/publishers/strategies/acm.py +27 -0
- litloop/publishers/strategies/acs.py +42 -0
- litloop/publishers/strategies/aip.py +27 -0
- litloop/publishers/strategies/aps.py +29 -0
- litloop/publishers/strategies/asce.py +28 -0
- litloop/publishers/strategies/base.py +108 -0
- litloop/publishers/strategies/copernicus.py +24 -0
- litloop/publishers/strategies/elsevier.py +66 -0
- litloop/publishers/strategies/generic.py +39 -0
- litloop/publishers/strategies/ieee.py +28 -0
- litloop/publishers/strategies/iop.py +27 -0
- litloop/publishers/strategies/nature.py +27 -0
- litloop/publishers/strategies/oxford.py +27 -0
- litloop/publishers/strategies/registry.py +83 -0
- litloop/publishers/strategies/royalsociety.py +28 -0
- litloop/publishers/strategies/rsc.py +27 -0
- litloop/publishers/strategies/sage.py +30 -0
- litloop/publishers/strategies/science.py +27 -0
- litloop/publishers/strategies/springer.py +34 -0
- litloop/publishers/strategies/tandfonline.py +32 -0
- litloop/publishers/strategies/wiley.py +32 -0
- litloop/publishers/supplementary.py +219 -0
- litloop/quota.py +202 -0
- litloop/search/__init__.py +1 -0
- litloop/search/abstracts.py +291 -0
- litloop/search/deep.py +1216 -0
- litloop/search/quick.py +1102 -0
- litloop/search/scansci_find.py +410 -0
- litloop/search/screening.py +225 -0
- litloop/search/title_to_doi.py +163 -0
- litloop/search/watches.py +124 -0
- litloop/server.py +1731 -0
- litloop/sources/__init__.py +1339 -0
- litloop/sources/_batch.py +529 -0
- litloop/sources/_index.py +221 -0
- litloop/sources/_routes.py +290 -0
- litloop/sources/altcha.py +90 -0
- litloop/sources/arxiv.py +45 -0
- litloop/sources/attempt.py +91 -0
- litloop/sources/carsi.py +74 -0
- litloop/sources/core_api.py +46 -0
- litloop/sources/crossref.py +162 -0
- litloop/sources/elsevier_api.py +620 -0
- litloop/sources/elsevier_check.py +274 -0
- litloop/sources/europepmc.py +81 -0
- litloop/sources/ezproxy.py +317 -0
- litloop/sources/instsci.py +1295 -0
- litloop/sources/libgen.py +116 -0
- litloop/sources/nature.py +39 -0
- litloop/sources/oa_discovery.py +135 -0
- litloop/sources/openaire.py +122 -0
- litloop/sources/openalex.py +100 -0
- litloop/sources/publishers.py +684 -0
- litloop/sources/sage_cn.py +139 -0
- litloop/sources/scibban.py +10 -0
- litloop/sources/scihub.py +1379 -0
- litloop/sources/scihub_domains.py +203 -0
- litloop/sources/scihub_speed.py +187 -0
- litloop/sources/scoring.py +250 -0
- litloop/sources/semantic_scholar.py +146 -0
- litloop/sources/springer_tdm.py +172 -0
- litloop/sources/unpaywall.py +116 -0
- litloop/sources/vpnsci.py +38 -0
- litloop/store.py +264 -0
- litloop/templates/index.html +347 -0
- litloop/terms/__init__.py +1 -0
- litloop/terms/glossary.py +422 -0
- litloop/terms/spelling.py +89 -0
- litloop/terms/text.py +106 -0
- litloop/tor/__init__.py +1 -0
- litloop/tor/embedded.py +371 -0
- litloop/tor/proxy.py +110 -0
- litloop/updates.py +148 -0
- litloop/zotero/__init__.py +1 -0
- litloop/zotero/bridge.py +309 -0
- litloop/zotero/client.py +317 -0
- litloop-1.18.3.dist-info/METADATA +347 -0
- litloop-1.18.3.dist-info/RECORD +176 -0
- litloop-1.18.3.dist-info/WHEEL +5 -0
- litloop-1.18.3.dist-info/entry_points.txt +2 -0
- litloop-1.18.3.dist-info/licenses/LICENSE +197 -0
- litloop-1.18.3.dist-info/top_level.txt +1 -0
litloop/diagnostics.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""Everything a bug report needs, in one zip: no PDFs, no credentials.
|
|
2
|
+
|
|
3
|
+
The app's "导出诊断包" button and `litloop diagnose` both land here. The point
|
|
4
|
+
is that a user who says "it doesn't work" can hand over one file that says
|
|
5
|
+
which version, which Python, which settings (keys masked) and what the last
|
|
6
|
+
few hundred log lines were — without us asking them to run a dozen commands.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import platform
|
|
13
|
+
import re
|
|
14
|
+
import sys
|
|
15
|
+
import zipfile
|
|
16
|
+
from datetime import datetime
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from . import __version__
|
|
21
|
+
from .config import DATA_DIR, load_config
|
|
22
|
+
from .log import get_logger, recent
|
|
23
|
+
|
|
24
|
+
log = get_logger()
|
|
25
|
+
|
|
26
|
+
_SECRET_NAME = re.compile(r"(api_key|token|secret|password|cookie|session_id)", re.I)
|
|
27
|
+
_KEEP_EMPTY = object()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def redact(value: Any, key: str = "") -> Any:
|
|
31
|
+
"""Mask anything that looks like a credential, keep the shape of everything else."""
|
|
32
|
+
if isinstance(value, dict):
|
|
33
|
+
return {k: redact(v, k) for k, v in value.items()}
|
|
34
|
+
if isinstance(value, list):
|
|
35
|
+
return [redact(v, key) for v in value]
|
|
36
|
+
if _SECRET_NAME.search(key) and isinstance(value, str) and value.strip():
|
|
37
|
+
return "***"
|
|
38
|
+
return value
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _components() -> dict[str, Any]:
|
|
42
|
+
try:
|
|
43
|
+
from .optional import COMPONENTS, installed
|
|
44
|
+
except Exception:
|
|
45
|
+
return {}
|
|
46
|
+
return {key: {"label": info.get("label", key), "installed": bool(installed(key))}
|
|
47
|
+
for key, info in COMPONENTS.items()}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _uv() -> str:
|
|
51
|
+
try:
|
|
52
|
+
from .optional import uv_command
|
|
53
|
+
found = uv_command()
|
|
54
|
+
except Exception:
|
|
55
|
+
return ""
|
|
56
|
+
return str(found) if found else ""
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _data_dir_summary() -> dict[str, Any]:
|
|
60
|
+
"""Counts only — enough to see whether something is empty or huge."""
|
|
61
|
+
summary: dict[str, Any] = {"path": str(DATA_DIR)}
|
|
62
|
+
for name in ("papers", "downloads", "screening", "exports", "cache", "packages"):
|
|
63
|
+
folder = DATA_DIR / name
|
|
64
|
+
if not folder.is_dir():
|
|
65
|
+
summary[name] = 0
|
|
66
|
+
continue
|
|
67
|
+
try:
|
|
68
|
+
summary[name] = sum(1 for item in folder.iterdir() if item.is_file())
|
|
69
|
+
except OSError:
|
|
70
|
+
summary[name] = -1
|
|
71
|
+
return summary
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def collect(config: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
75
|
+
"""The JSON that goes into the bundle."""
|
|
76
|
+
config = load_config() if config is None else config
|
|
77
|
+
return {
|
|
78
|
+
"generated": datetime.now().isoformat(timespec="seconds"),
|
|
79
|
+
"app": {
|
|
80
|
+
"version": __version__,
|
|
81
|
+
"python": platform.python_version(),
|
|
82
|
+
"executable": sys.executable,
|
|
83
|
+
"frozen": bool(getattr(sys, "frozen", False)),
|
|
84
|
+
},
|
|
85
|
+
"system": {
|
|
86
|
+
"os": platform.system(),
|
|
87
|
+
"release": platform.release(),
|
|
88
|
+
"version": platform.version(),
|
|
89
|
+
"machine": platform.machine(),
|
|
90
|
+
"platform": platform.platform(terse=True),
|
|
91
|
+
},
|
|
92
|
+
"paths": _data_dir_summary(),
|
|
93
|
+
"settings": redact(dict(config)),
|
|
94
|
+
"components": _components(),
|
|
95
|
+
"uv": _uv(),
|
|
96
|
+
"log": recent(300),
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _bundle_name(when: datetime) -> str:
|
|
101
|
+
return f"litloop-diagnostics-{when.strftime('%Y%m%d-%H%M%S')}.zip"
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def write_bundle(path: str | Path | None = None, config: dict[str, Any] | None = None) -> Path:
|
|
105
|
+
"""Write the zip and return its path. `path` may be a directory or a file name."""
|
|
106
|
+
now = datetime.now()
|
|
107
|
+
target = Path(path) if path else (DATA_DIR / "exports" / _bundle_name(now))
|
|
108
|
+
if target.is_dir() or (not target.suffix and not target.exists()):
|
|
109
|
+
target = target / _bundle_name(now)
|
|
110
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
111
|
+
|
|
112
|
+
data = collect(config)
|
|
113
|
+
with zipfile.ZipFile(target, "w", zipfile.ZIP_DEFLATED) as archive:
|
|
114
|
+
archive.writestr("diagnostics.json", json.dumps(data, ensure_ascii=False, indent=2))
|
|
115
|
+
archive.writestr("log.txt", "\n".join(data["log"]) or "(没有日志)")
|
|
116
|
+
archive.writestr("README.txt", _README)
|
|
117
|
+
log.info("诊断包写到了 %s", target)
|
|
118
|
+
return target
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
_README = """这个压缩包里有什么
|
|
122
|
+
==================
|
|
123
|
+
diagnostics.json 版本、系统信息、数据目录里各类文件的数量、脱敏后的设置、可选组件与 uv 的状态
|
|
124
|
+
log.txt 本次运行的最近 300 行日志
|
|
125
|
+
不含 PDF、不含 Zotero 数据、不含任何 API Key 与 cookie(设置里的密钥已显示为 ***)。
|
|
126
|
+
"""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""PDF download pipeline, fetchers, file naming, and progress reporting."""
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Is a DOI registered? Asked once before a paper is downloaded, so a mistyped
|
|
2
|
+
or made-up DOI fails at once instead of running every source and school route.
|
|
3
|
+
|
|
4
|
+
doi.org's handle API knows the DOIs of every registration agency (Crossref,
|
|
5
|
+
DataCite, mEDRA, ...): ``/api/handles/<doi>`` answers 200 with
|
|
6
|
+
``responseCode`` 1 for a registered DOI and 404 with ``responseCode`` 100 for
|
|
7
|
+
one that is not (checked 2026-10-23). Anything else (no network, a timeout, an
|
|
8
|
+
odd answer) leaves the question open and the paper is downloaded as before.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import threading
|
|
14
|
+
from urllib.parse import quote
|
|
15
|
+
|
|
16
|
+
import requests
|
|
17
|
+
|
|
18
|
+
_KNOWN: dict[str, bool] = {}
|
|
19
|
+
_LOCK = threading.Lock()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def registered(doi: str, timeout: float = 6.0) -> bool | None:
|
|
23
|
+
"""True or False when doi.org answered, None when it could not tell."""
|
|
24
|
+
key = (doi or "").strip().lower()
|
|
25
|
+
if not key.startswith("10."):
|
|
26
|
+
return None
|
|
27
|
+
with _LOCK:
|
|
28
|
+
if key in _KNOWN:
|
|
29
|
+
return _KNOWN[key]
|
|
30
|
+
try:
|
|
31
|
+
r = requests.get(f"https://doi.org/api/handles/{quote(key, safe='/')}", params={"type": "URL"},
|
|
32
|
+
timeout=timeout)
|
|
33
|
+
code = r.json().get("responseCode")
|
|
34
|
+
except (requests.RequestException, ValueError, AttributeError):
|
|
35
|
+
return None
|
|
36
|
+
if r.status_code == 200 and code == 1:
|
|
37
|
+
answer = True
|
|
38
|
+
elif r.status_code == 404 and code == 100:
|
|
39
|
+
answer = False
|
|
40
|
+
else:
|
|
41
|
+
return None
|
|
42
|
+
with _LOCK:
|
|
43
|
+
_KNOWN[key] = answer
|
|
44
|
+
return answer
|