papersearch 0.6.11 → 0.7.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 +661 -21
- package/NOTICE +51 -0
- package/README.en.md +13 -13
- package/README.md +13 -13
- package/assets/federation-map.en.png +0 -0
- package/assets/federation-map.png +0 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batch.d.ts +24 -16
- package/dist/capabilities/download/batch/batch.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batch.js +416 -286
- package/dist/capabilities/download/batch/batch.js.map +1 -0
- package/dist/capabilities/download/batch/batchFolder.d.ts +21 -0
- package/dist/capabilities/download/batch/batchFolder.d.ts.map +1 -0
- package/dist/capabilities/download/batch/batchFolder.js +206 -0
- package/dist/capabilities/download/batch/batchFolder.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batchPapers.d.ts +1 -1
- package/dist/capabilities/download/batch/batchPapers.d.ts.map +1 -0
- package/dist/capabilities/download/batch/batchPapers.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batchSummary.d.ts +4 -8
- package/dist/capabilities/download/batch/batchSummary.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batchSummary.js +91 -32
- package/dist/capabilities/download/batch/batchSummary.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/networkLoss.d.ts +1 -1
- package/dist/capabilities/download/batch/networkLoss.d.ts.map +1 -0
- package/dist/capabilities/download/batch/networkLoss.js.map +1 -0
- package/dist/capabilities/download/batch/resume.d.ts +76 -0
- package/dist/capabilities/download/batch/resume.d.ts.map +1 -0
- package/dist/capabilities/download/batch/resume.js +231 -0
- package/dist/capabilities/download/batch/resume.js.map +1 -0
- package/dist/capabilities/download/content/markdown/pageVisit.d.ts +14 -0
- package/dist/capabilities/download/content/markdown/pageVisit.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/pageVisit.js +52 -0
- package/dist/capabilities/download/content/markdown/pageVisit.js.map +1 -0
- package/dist/capabilities/download/content/markdown/pro.d.ts +87 -0
- package/dist/capabilities/download/content/markdown/pro.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/pro.js +109 -0
- package/dist/capabilities/download/content/markdown/pro.js.map +1 -0
- package/dist/capabilities/download/content/markdown/shortfall.d.ts +34 -0
- package/dist/capabilities/download/content/markdown/shortfall.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/shortfall.js +99 -0
- package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -0
- package/dist/capabilities/download/content/markdown/stats.d.ts +9 -0
- package/dist/capabilities/download/content/markdown/stats.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/stats.js +39 -0
- package/dist/capabilities/download/content/markdown/stats.js.map +1 -0
- package/dist/capabilities/download/content/markdown/step.d.ts +50 -0
- package/dist/capabilities/download/content/markdown/step.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/step.js +343 -0
- package/dist/capabilities/download/content/markdown/step.js.map +1 -0
- package/dist/capabilities/download/content/markdown/types.d.ts +120 -0
- package/dist/capabilities/download/content/markdown/types.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/types.js +8 -0
- package/dist/capabilities/download/content/markdown/types.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/DownloadTier.d.ts +13 -4
- package/dist/capabilities/download/content/pdf/DownloadTier.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/DownloadTier.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/OpenAccessFallbackService.d.ts +5 -5
- package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/OpenAccessFallbackService.js +24 -13
- package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.js.map +1 -0
- package/dist/capabilities/download/content/pdf/arxiv.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/arxiv.js +2 -2
- package/dist/capabilities/download/content/pdf/arxiv.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/identity.d.ts +1 -1
- package/dist/capabilities/download/content/pdf/identity.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/identity.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/oaHosts.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/open/oaHosts.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/pmcCloud.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/pmcCloud.js +2 -2
- package/dist/capabilities/download/content/pdf/open/pmcCloud.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/publisherApi/elsevier.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/elsevier.js +3 -3
- package/dist/capabilities/download/content/pdf/open/publisherApi/elsevier.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/publisherApi/index.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/open/publisherApi/index.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/publisherApi/springer.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/springer.js +3 -3
- package/dist/capabilities/download/content/pdf/open/publisherApi/springer.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/directPdfUrl.d.ts +5 -0
- package/dist/capabilities/download/content/pdf/open/tiers/directPdfUrl.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/directPdfUrl.js +3 -3
- package/dist/capabilities/download/content/pdf/open/tiers/directPdfUrl.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/preprint.d.ts +5 -0
- package/dist/capabilities/download/content/pdf/open/tiers/preprint.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/preprint.js +5 -5
- package/dist/capabilities/download/content/pdf/open/tiers/preprint.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/primary.d.ts +3 -0
- package/dist/capabilities/download/content/pdf/open/tiers/primary.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/primary.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/publisherApi.d.ts +1 -1
- package/dist/capabilities/download/content/pdf/open/tiers/publisherApi.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/publisherApi.js +5 -5
- package/dist/capabilities/download/content/pdf/open/tiers/publisherApi.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/repositories.d.ts +1 -1
- package/dist/capabilities/download/content/pdf/open/tiers/repositories.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/repositories.js +2 -2
- package/dist/capabilities/download/content/pdf/open/tiers/repositories.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.d.ts +3 -0
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/unpaywall.d.ts +3 -0
- package/dist/capabilities/download/content/pdf/open/tiers/unpaywall.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/unpaywall.js +2 -2
- package/dist/capabilities/download/content/pdf/open/tiers/unpaywall.js.map +1 -0
- package/dist/capabilities/download/content/pdf/school.d.ts +4 -0
- package/dist/capabilities/download/content/pdf/school.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery/tiers/entitledAccess.js → download/content/pdf/school.js} +16 -40
- package/dist/capabilities/download/content/pdf/school.js.map +1 -0
- package/dist/capabilities/download/content/supplements/fetch.d.ts +27 -0
- package/dist/capabilities/download/content/supplements/fetch.d.ts.map +1 -0
- package/dist/capabilities/download/content/supplements/fetch.js +150 -0
- package/dist/capabilities/download/content/supplements/fetch.js.map +1 -0
- package/dist/capabilities/download/content/supplements/shortfall.d.ts +11 -0
- package/dist/capabilities/download/content/supplements/shortfall.d.ts.map +1 -0
- package/dist/capabilities/download/content/supplements/shortfall.js +24 -0
- package/dist/capabilities/download/content/supplements/shortfall.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/handler.d.ts +12 -4
- package/dist/capabilities/download/handler.d.ts.map +1 -0
- package/dist/capabilities/download/handler.js +275 -0
- package/dist/capabilities/download/handler.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/index.d.ts +3 -3
- package/dist/capabilities/download/index.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/index.js +2 -2
- package/dist/capabilities/download/index.js.map +1 -0
- package/dist/capabilities/download/outputLayout.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/outputLayout.js +63 -6
- package/dist/capabilities/download/outputLayout.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/schemas.d.ts +143 -18
- package/dist/capabilities/download/schemas.d.ts.map +1 -0
- package/dist/capabilities/download/schemas.js +126 -0
- package/dist/capabilities/download/schemas.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/tools.d.ts +68 -6
- package/dist/capabilities/download/tools.d.ts.map +1 -0
- package/dist/capabilities/download/tools.js +197 -0
- package/dist/capabilities/download/tools.js.map +1 -0
- package/dist/capabilities/download/types.d.ts +222 -0
- package/dist/capabilities/download/types.d.ts.map +1 -0
- package/dist/capabilities/download/types.js +7 -0
- package/dist/capabilities/download/types.js.map +1 -0
- package/dist/cli.js +98 -17
- package/dist/cli.js.map +1 -1
- package/dist/config/edition.d.ts +8 -0
- package/dist/config/edition.d.ts.map +1 -0
- package/dist/config/edition.js +31 -0
- package/dist/config/edition.js.map +1 -0
- package/dist/core/handleToolCall.d.ts +1 -1
- package/dist/core/handleToolCall.d.ts.map +1 -1
- package/dist/core/handleToolCall.js +1 -1
- package/dist/core/handleToolCall.js.map +1 -1
- package/dist/core/schemas.d.ts +1 -1
- package/dist/core/schemas.d.ts.map +1 -1
- package/dist/core/schemas.js +1 -1
- package/dist/core/schemas.js.map +1 -1
- package/dist/core/tools.d.ts +2 -1
- package/dist/core/tools.d.ts.map +1 -1
- package/dist/core/tools.js +8 -2
- package/dist/core/tools.js.map +1 -1
- package/dist/infrastructure/pdf/PdfIdentity.d.ts.map +1 -1
- package/dist/infrastructure/pdf/PdfIdentity.js +76 -5
- package/dist/infrastructure/pdf/PdfIdentity.js.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.d.ts +12 -2
- package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.js +39 -11
- package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts +9 -6
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +81 -43
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolAttempt.js +10 -3
- package/dist/infrastructure/school/SchoolAttempt.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolMcpClient.d.ts +17 -0
- package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolMcpClient.js +99 -10
- package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolProgress.d.ts +1 -0
- package/dist/infrastructure/school/SchoolProgress.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolProgress.js +1 -0
- package/dist/infrastructure/school/SchoolProgress.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolReadiness.d.ts +7 -1
- package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolReadiness.js +10 -2
- package/dist/infrastructure/school/SchoolReadiness.js.map +1 -0
- package/dist/infrastructure/school/SchoolResultNormalizer.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolResultNormalizer.js +72 -3
- package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/index.d.ts +2 -1
- package/dist/infrastructure/school/index.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/index.js +3 -2
- package/dist/infrastructure/school/index.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/types.d.ts +78 -3
- package/dist/infrastructure/school/types.d.ts.map +1 -0
- package/dist/infrastructure/school/types.js +5 -0
- package/dist/infrastructure/school/types.js.map +1 -0
- package/dist/management/capability-profile/schoolReadiness.d.ts +1 -1
- package/dist/management/capability-profile/schoolReadiness.d.ts.map +1 -1
- package/dist/management/capability-profile/schoolReadiness.js +1 -1
- package/dist/management/capability-profile/schoolReadiness.js.map +1 -1
- package/dist/management/failures/exportReport.d.ts +6 -0
- package/dist/management/failures/exportReport.d.ts.map +1 -1
- package/dist/management/failures/exportReport.js +28 -18
- package/dist/management/failures/exportReport.js.map +1 -1
- package/dist/management/failures/index.d.ts +3 -0
- package/dist/management/failures/index.d.ts.map +1 -1
- package/dist/management/failures/index.js +5 -2
- package/dist/management/failures/index.js.map +1 -1
- package/dist/management/failures/markdownReport.d.ts +55 -0
- package/dist/management/failures/markdownReport.d.ts.map +1 -0
- package/dist/management/failures/markdownReport.js +96 -0
- package/dist/management/failures/markdownReport.js.map +1 -0
- package/dist/management/pro/install.d.ts +58 -0
- package/dist/management/pro/install.d.ts.map +1 -0
- package/dist/management/pro/install.js +235 -0
- package/dist/management/pro/install.js.map +1 -0
- package/dist/management/reports/index.d.ts.map +1 -1
- package/dist/management/reports/index.js +4 -1
- package/dist/management/reports/index.js.map +1 -1
- package/dist/management/school/autoUpdate.d.ts +4 -3
- package/dist/management/school/autoUpdate.d.ts.map +1 -1
- package/dist/management/school/autoUpdate.js +6 -4
- package/dist/management/school/autoUpdate.js.map +1 -1
- package/dist/management/school/cliProgress.d.ts +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/host.js +1 -1
- package/dist/management/school/host.js.map +1 -1
- package/dist/management/school/installer.d.ts +1 -2
- package/dist/management/school/installer.d.ts.map +1 -1
- package/dist/management/school/installer.js.map +1 -1
- package/dist/management/school/legacy.js +1 -1
- package/dist/management/school/legacy.js.map +1 -1
- package/dist/management/school/settingsWindow.d.ts +14 -3
- package/dist/management/school/settingsWindow.d.ts.map +1 -1
- package/dist/management/school/settingsWindow.js +14 -4
- package/dist/management/school/settingsWindow.js.map +1 -1
- package/dist/management/skills/autoSync.d.ts +3 -3
- package/dist/management/skills/autoSync.d.ts.map +1 -1
- package/dist/management/skills/autoSync.js +13 -20
- package/dist/management/skills/autoSync.js.map +1 -1
- package/dist/services/OpenAccessFallbackService.d.ts +3 -3
- package/dist/services/OpenAccessFallbackService.d.ts.map +1 -1
- package/dist/services/OpenAccessFallbackService.js +1 -1
- package/dist/services/OpenAccessFallbackService.js.map +1 -1
- package/dist/skills/SkillInstaller.d.ts +26 -0
- package/dist/skills/SkillInstaller.d.ts.map +1 -1
- package/dist/skills/SkillInstaller.js +80 -10
- package/dist/skills/SkillInstaller.js.map +1 -1
- package/package.json +10 -2
- package/school/LICENSE +661 -21
- package/school/LICENSE-scansci-pdf +21 -0
- package/school/NOTICE +10 -0
- package/school/README.md +1 -1
- package/school/paper_search_school/_core/__init__.py +2 -1
- package/school/paper_search_school/adapters/__init__.py +3 -3
- package/school/paper_search_school/adapters/acm/__init__.py +7 -1
- package/school/paper_search_school/adapters/acs/__init__.py +4 -0
- package/school/paper_search_school/adapters/aha_journals/__init__.py +5 -1
- package/school/paper_search_school/adapters/aip/__init__.py +17 -0
- package/school/paper_search_school/adapters/ams/__init__.py +36 -0
- package/school/paper_search_school/adapters/annual_reviews/__init__.py +24 -1
- package/school/paper_search_school/adapters/aps/__init__.py +118 -0
- package/school/paper_search_school/adapters/asce/__init__.py +7 -1
- package/school/paper_search_school/adapters/base.py +21 -1
- package/school/paper_search_school/adapters/bmj/__init__.py +54 -0
- package/school/paper_search_school/adapters/copernicus/__init__.py +35 -0
- package/school/paper_search_school/adapters/dovepress/__init__.py +31 -0
- package/school/paper_search_school/adapters/elsevier/__init__.py +33 -0
- package/school/paper_search_school/adapters/frontiers/__init__.py +46 -1
- package/school/paper_search_school/adapters/ieee/__init__.py +94 -2
- package/school/paper_search_school/adapters/iop/__init__.py +65 -0
- package/school/paper_search_school/adapters/jama/__init__.py +4 -0
- package/school/paper_search_school/adapters/karger/__init__.py +6 -1
- package/school/paper_search_school/adapters/lww/__init__.py +3 -0
- package/school/paper_search_school/adapters/lww/ovid.py +28 -0
- package/school/paper_search_school/adapters/mdpi/__init__.py +73 -0
- package/school/paper_search_school/adapters/nejm/__init__.py +5 -1
- package/school/paper_search_school/adapters/neurology/__init__.py +5 -1
- package/school/paper_search_school/adapters/optica/__init__.py +49 -0
- package/school/paper_search_school/adapters/oup/__init__.py +34 -2
- package/school/paper_search_school/adapters/platforms/atypon/__init__.py +83 -2
- package/school/paper_search_school/adapters/platforms/figshare/__init__.py +0 -3
- package/school/paper_search_school/adapters/platforms/silverchair/__init__.py +76 -0
- package/school/paper_search_school/adapters/plos/__init__.py +85 -2
- package/school/paper_search_school/adapters/pnas/__init__.py +5 -1
- package/school/paper_search_school/adapters/royal_society/__init__.py +17 -0
- package/school/paper_search_school/adapters/rsc/__init__.py +4 -1
- package/school/paper_search_school/adapters/sage/__init__.py +6 -0
- package/school/paper_search_school/adapters/science/__init__.py +5 -1
- package/school/paper_search_school/adapters/springer/__init__.py +102 -0
- package/school/paper_search_school/adapters/taylor_francis/__init__.py +11 -1
- package/school/paper_search_school/adapters/thieme/__init__.py +46 -0
- package/school/paper_search_school/adapters/wiley/__init__.py +28 -0
- package/school/paper_search_school/adapters/world_scientific/__init__.py +15 -4
- package/school/paper_search_school/assets/capsule.html +599 -38
- package/school/paper_search_school/assets/capsule_en.json +309 -7
- package/school/paper_search_school/browser/__init__.py +5 -2
- package/school/paper_search_school/browser/backend.py +161 -9
- package/school/paper_search_school/browser/batch_session.py +76 -2
- package/school/paper_search_school/browser/challenge/__init__.py +13 -0
- package/school/paper_search_school/browser/{challenges.py → challenge/detection.py} +1 -1
- package/school/paper_search_school/browser/{challenge_interaction.py → challenge/interaction.py} +92 -19
- package/school/paper_search_school/browser/challenge/pointer.py +228 -0
- package/school/paper_search_school/browser/challenge/prompt.py +154 -0
- package/school/paper_search_school/browser/challenge/warmup.py +90 -0
- package/school/paper_search_school/browser/driver.py +12 -0
- package/school/paper_search_school/browser/profiles.py +54 -3
- package/school/paper_search_school/browser/watchdog.py +8 -0
- package/school/paper_search_school/cli.py +150 -10
- package/school/paper_search_school/cold_start.py +5 -2
- package/school/paper_search_school/config.py +25 -1
- package/school/paper_search_school/download_diagnostics.py +2 -1
- package/school/paper_search_school/edition.py +22 -0
- package/school/paper_search_school/engine/access_rules.py +62 -2
- package/school/paper_search_school/engine/batch.py +56 -12
- package/school/paper_search_school/engine/batch_access.py +12 -1
- package/school/paper_search_school/engine/batch_capture.py +309 -9
- package/school/paper_search_school/engine/batch_common.py +3 -1
- package/school/paper_search_school/engine/batch_institution.py +145 -21
- package/school/paper_search_school/engine/batch_login.py +554 -21
- package/school/paper_search_school/engine/batch_waits.py +76 -1
- package/school/paper_search_school/engine/bridge.py +118 -7
- package/school/paper_search_school/engine/fulltext_page.py +340 -0
- package/school/paper_search_school/engine/pdf_guard.py +65 -5
- package/school/paper_search_school/engine/router.py +3 -2
- package/school/paper_search_school/engine/supplement_transfer.py +22 -7
- package/school/paper_search_school/engine/supplements.py +5 -8
- package/school/paper_search_school/federations/__init__.py +9 -6
- package/school/paper_search_school/{carsi_schools.py → federations/carsi.py} +1 -1
- package/school/paper_search_school/federations/{builtin → data/asia}/cstcloud.json +2 -2
- package/school/paper_search_school/federations/{builtin → data/europe}/eduidhu.json +2 -2
- package/school/paper_search_school/login_routes.py +45 -0
- package/school/paper_search_school/markdown_report.py +426 -0
- package/school/paper_search_school/orchestrator.py +25 -1
- package/school/paper_search_school/pro_status.py +192 -0
- package/school/paper_search_school/progress_capsule.py +192 -2
- package/school/paper_search_school/progress_reporter.py +92 -14
- package/school/paper_search_school/progress_status.py +1 -1
- package/school/paper_search_school/progress_view.py +148 -28
- package/school/paper_search_school/publishers/profiles.py +6 -0
- package/school/paper_search_school/rate_limit.py +7 -0
- package/school/paper_search_school/report_sanitizer.py +25 -11
- package/school/paper_search_school/school_login.py +373 -0
- package/school/paper_search_school/schools/__init__.py +7 -0
- package/school/paper_search_school/{federations/schools.py → schools/lookup.py} +3 -3
- package/school/paper_search_school/schools/saved.py +111 -0
- package/school/paper_search_school/server.py +53 -9
- package/school/paper_search_school/user_settings.py +14 -0
- package/school/pyproject.toml +3 -2
- package/skills/paper-search/SKILL.md +11 -12
- package/skills/paper-search/references/browser-download.md +19 -15
- package/skills/paper-search/references/capability-routing.md +1 -1
- package/skills/paper-search/references/cli-contract.md +7 -5
- package/skills/paper-search/references/management-layer.md +3 -3
- package/skills/paper-search/references/publisher-support.md +5 -5
- package/skills/paper-search/references/school-setup.md +14 -0
- package/skills/paper-search/references/troubleshooting.md +0 -1
- package/assets/ask-with-skill.png +0 -0
- package/dist/capabilities/pdf-discovery/DownloadTier.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/DownloadTier.js.map +0 -1
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js.map +0 -1
- package/dist/capabilities/pdf-discovery/arxiv.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/arxiv.js.map +0 -1
- package/dist/capabilities/pdf-discovery/batch.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/batch.js.map +0 -1
- package/dist/capabilities/pdf-discovery/batchPapers.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/batchPapers.js.map +0 -1
- package/dist/capabilities/pdf-discovery/batchSummary.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/batchSummary.js.map +0 -1
- package/dist/capabilities/pdf-discovery/handler.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/handler.js +0 -166
- package/dist/capabilities/pdf-discovery/handler.js.map +0 -1
- package/dist/capabilities/pdf-discovery/identity.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/identity.js.map +0 -1
- package/dist/capabilities/pdf-discovery/index.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/index.js.map +0 -1
- package/dist/capabilities/pdf-discovery/networkLoss.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/networkLoss.js.map +0 -1
- package/dist/capabilities/pdf-discovery/oaHosts.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/oaHosts.js.map +0 -1
- package/dist/capabilities/pdf-discovery/outputLayout.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/outputLayout.js.map +0 -1
- package/dist/capabilities/pdf-discovery/pmcCloud.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/pmcCloud.js.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/elsevier.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/elsevier.js.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/index.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/index.js.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/springer.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/springer.js.map +0 -1
- package/dist/capabilities/pdf-discovery/resume.d.ts +0 -22
- package/dist/capabilities/pdf-discovery/resume.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/resume.js +0 -124
- package/dist/capabilities/pdf-discovery/resume.js.map +0 -1
- package/dist/capabilities/pdf-discovery/schemas.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/schemas.js +0 -75
- package/dist/capabilities/pdf-discovery/schemas.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolAttempt.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolAttempt.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolMcpClient.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolMcpClient.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolProgress.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolProgress.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolReadiness.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolReadiness.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolResultNormalizer.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolResultNormalizer.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/index.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/index.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/types.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/types.js +0 -2
- package/dist/capabilities/pdf-discovery/school/types.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.d.ts +0 -5
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.d.ts +0 -10
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/preprint.d.ts +0 -5
- package/dist/capabilities/pdf-discovery/tiers/preprint.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/preprint.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/primary.d.ts +0 -3
- package/dist/capabilities/pdf-discovery/tiers/primary.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/primary.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/publisherApi.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/publisherApi.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/repositories.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/repositories.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/scihub.d.ts +0 -3
- package/dist/capabilities/pdf-discovery/tiers/scihub.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/scihub.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.d.ts +0 -3
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tools.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tools.js +0 -146
- package/dist/capabilities/pdf-discovery/tools.js.map +0 -1
- package/dist/capabilities/pdf-discovery/types.d.ts +0 -102
- package/dist/capabilities/pdf-discovery/types.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/types.js +0 -2
- package/dist/capabilities/pdf-discovery/types.js.map +0 -1
- /package/dist/capabilities/{pdf-discovery → download/batch}/batchPapers.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/batch}/networkLoss.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf}/DownloadTier.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf}/arxiv.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf}/identity.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/oaHosts.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/oaHosts.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/pmcCloud.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/elsevier.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/index.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/index.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/springer.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/primary.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/scihub.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download}/outputLayout.d.ts +0 -0
- /package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolAttempt.d.ts +0 -0
- /package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolResultNormalizer.d.ts +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/eduidbf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/eduidma.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/eduidtg.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/fidern.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/garnet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/maren.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/ngrenid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/rafiki.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/rif.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/safire.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/ternet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/caf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/cafe.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/cofre.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/colfire.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/fenix.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/incommon.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/minga.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/azsciencenet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/carsi.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/cynet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/gakunin.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/hkaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/infed.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/irfed.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/iucc.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/kafe.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/liaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/maeen.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/omren.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/pkifed.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/sgaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/sifulan.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/tigerfed.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/yetkim.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/aaieduhr.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/aaiedumk.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/aconet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/arnesaai.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/belnet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/bif.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/dfnaai.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/edugate.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/eduidcz.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/eduidlu.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/febas.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/feide.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/grnet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/haka.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/iamres.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/idedume.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/idem.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/laife.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/leaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/litnet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/peano.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/pionierid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/rash.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/rctsaai.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/renater.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/ricerkanet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/roedunetid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/safeid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/sir.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/surfconext.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/swamid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/switchaai.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/taat.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/ukfederation.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/wayf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/global}/openathens.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/oceania}/aaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/oceania}/tuakiri.json +0 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"""The school's sign-in filled in for the user, a PaperSearch Pro feature.
|
|
2
|
+
|
|
3
|
+
This is the public side: where the account is kept, which pages may be given it, how often,
|
|
4
|
+
and the loading of Pro's part, which finds the form, fills it, submits it and says how that
|
|
5
|
+
went. Without Pro, or for a school Pro has not tested, nothing is filled and the user signs in
|
|
6
|
+
as before.
|
|
7
|
+
|
|
8
|
+
The account is kept in the backend's config file (user, 2026-11-19), under ``school_logins``
|
|
9
|
+
by the school's entityID; ``config show`` masks it and reports leave it out (report_sanitizer).
|
|
10
|
+
Nothing here writes the account into an event, a log or a diagnostic file.
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import importlib.util
|
|
15
|
+
import json
|
|
16
|
+
import logging
|
|
17
|
+
import os
|
|
18
|
+
import sys
|
|
19
|
+
import time
|
|
20
|
+
from dataclasses import dataclass, field
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Any, Callable
|
|
23
|
+
from urllib.parse import urlparse
|
|
24
|
+
|
|
25
|
+
from .edition import pro_features
|
|
26
|
+
|
|
27
|
+
log = logging.getLogger(__name__)
|
|
28
|
+
|
|
29
|
+
#: Pro's part, written by PaperSearch once Pro's access check has passed (pro.ts): the package's
|
|
30
|
+
#: ``school_login/__init__.py`` (its schools in ``schools/<federation>/``), or a single file.
|
|
31
|
+
MODULE_ENV = "PAPER_SEARCH_PRO_SCHOOL_LOGIN"
|
|
32
|
+
#: Maintainers testing a school Pro lists as still being tested ("trial").
|
|
33
|
+
TRIAL_ENV = "PAPER_SEARCH_SCHOOL_LOGIN_TRIAL"
|
|
34
|
+
#: Maintainers surveying schools' sign-in pages without their accounts: "1", what Pro finds there and
|
|
35
|
+
#: whether the sign-in control takes a click (a trial click), nothing filled in or sent; "press", a
|
|
36
|
+
#: made-up account typed in and the control pressed for real, once, and what the school answered.
|
|
37
|
+
SURVEY_ENV = "PAPER_SEARCH_SCHOOL_LOGIN_SURVEY"
|
|
38
|
+
#: The interface between this file and Pro's part.
|
|
39
|
+
API = 1
|
|
40
|
+
CONFIG_KEY = "school_logins"
|
|
41
|
+
#: Sign-ins filled in per school and hour. About one an hour is normal (a school's sign-in
|
|
42
|
+
#: lasts an hour at the shortest seen); more means something keeps failing.
|
|
43
|
+
PER_HOUR = 6
|
|
44
|
+
HOUR = 3600
|
|
45
|
+
|
|
46
|
+
_loaded: tuple[str, Any] | None = None
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def module() -> Any | None:
|
|
50
|
+
"""Pro's part, or None: no Pro, its access not given, or another interface."""
|
|
51
|
+
global _loaded
|
|
52
|
+
path = os.environ.get(MODULE_ENV, "").strip()
|
|
53
|
+
if not path or not pro_features() or not Path(path).is_file():
|
|
54
|
+
return None
|
|
55
|
+
if _loaded is not None and _loaded[0] == path:
|
|
56
|
+
return _loaded[1]
|
|
57
|
+
name = "papersearch_pro_school_login"
|
|
58
|
+
package = [str(Path(path).parent)] if Path(path).name == "__init__.py" else None
|
|
59
|
+
try:
|
|
60
|
+
spec = importlib.util.spec_from_file_location(name, path, submodule_search_locations=package)
|
|
61
|
+
if spec is None or spec.loader is None:
|
|
62
|
+
return None
|
|
63
|
+
loaded = importlib.util.module_from_spec(spec)
|
|
64
|
+
sys.modules[name] = loaded # its own modules import it by name
|
|
65
|
+
spec.loader.exec_module(loaded)
|
|
66
|
+
except Exception as exc: # Pro's part does not load: no filling in, the downloads go on
|
|
67
|
+
sys.modules.pop(name, None)
|
|
68
|
+
log.warning("PaperSearch Pro's school sign-in did not load: %s: %s", type(exc).__name__, exc)
|
|
69
|
+
return None
|
|
70
|
+
if getattr(loaded, "API", None) != API:
|
|
71
|
+
log.warning("PaperSearch Pro's school sign-in has interface %s, this backend %s; update Pro",
|
|
72
|
+
getattr(loaded, "API", None), API)
|
|
73
|
+
return None
|
|
74
|
+
_loaded = (path, loaded)
|
|
75
|
+
return loaded
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def school_status(entity_id: str, pro: Any | None = None) -> str:
|
|
79
|
+
"""``verified`` (signed in for real), ``surveyed`` (its form filled in and pressed, the school's
|
|
80
|
+
"wrong password" read: user, 2026-11-19, enough), ``trial`` (being tested), or "" (not tested)."""
|
|
81
|
+
pro = pro if pro is not None else module()
|
|
82
|
+
if pro is None or not entity_id:
|
|
83
|
+
return ""
|
|
84
|
+
try:
|
|
85
|
+
status = str(pro.school_status(entity_id) or "")
|
|
86
|
+
except Exception:
|
|
87
|
+
return ""
|
|
88
|
+
return status if status in {"verified", "surveyed", "trial"} else ""
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def fills_for(entity_id: str, pro: Any | None = None) -> bool:
|
|
92
|
+
"""Whether Pro fills this school's sign-in in: tested or surveyed, or being tested by a maintainer."""
|
|
93
|
+
status = school_status(entity_id, pro)
|
|
94
|
+
return status in {"verified", "surveyed"} or (status == "trial" and os.environ.get(TRIAL_ENV) == "1")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# -- the account ------------------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
def _logins(config: dict[str, Any]) -> dict[str, Any]:
|
|
100
|
+
value = config.get(CONFIG_KEY)
|
|
101
|
+
return value if isinstance(value, dict) else {}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def saved(config: dict[str, Any], entity_id: str) -> dict[str, Any] | None:
|
|
105
|
+
"""The school's saved account ({username, password, enabled, off}), or None."""
|
|
106
|
+
entry = _logins(config).get(entity_id) if entity_id else None
|
|
107
|
+
if not isinstance(entry, dict) or not entry.get("username") or not entry.get("password"):
|
|
108
|
+
return None
|
|
109
|
+
return entry
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def masked(username: str) -> str:
|
|
113
|
+
"""The account as shown once saved: its first and last characters."""
|
|
114
|
+
name = str(username or "")
|
|
115
|
+
return name if len(name) <= 2 else name[0] + "*" * min(6, len(name) - 2) + name[-1]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def save(entity_id: str, username: str, password: str, *, enabled: bool = True) -> None:
|
|
119
|
+
"""Keep the school's account (``enabled``: whether Pro fills it in)."""
|
|
120
|
+
from . import config as cfg
|
|
121
|
+
|
|
122
|
+
if not entity_id:
|
|
123
|
+
raise ValueError("还没有设置学校")
|
|
124
|
+
current = cfg.load_config()
|
|
125
|
+
entry = _logins(current).get(entity_id) if isinstance(_logins(current).get(entity_id), dict) else {}
|
|
126
|
+
# A field left empty keeps what was saved: the switch, or one of the two changed.
|
|
127
|
+
username = str(username or "").strip() or str(entry.get("username") or "")
|
|
128
|
+
password = str(password or "") or str(entry.get("password") or "")
|
|
129
|
+
if not username:
|
|
130
|
+
raise ValueError("请填写账号")
|
|
131
|
+
if not password:
|
|
132
|
+
raise ValueError("请填写密码")
|
|
133
|
+
logins = dict(_logins(current))
|
|
134
|
+
logins[entity_id] = {"username": username, "password": password, "enabled": bool(enabled), "off": "",
|
|
135
|
+
"saved": time.strftime("%Y-%m-%d %H:%M")}
|
|
136
|
+
current[CONFIG_KEY] = logins
|
|
137
|
+
cfg.save_config(current)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def clear(entity_id: str) -> None:
|
|
141
|
+
from . import config as cfg
|
|
142
|
+
|
|
143
|
+
current = cfg.load_config()
|
|
144
|
+
logins = dict(_logins(current))
|
|
145
|
+
if logins.pop(entity_id, None) is not None:
|
|
146
|
+
current[CONFIG_KEY] = logins
|
|
147
|
+
cfg.save_config(current)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def turn_off(entity_id: str, why: str) -> None:
|
|
151
|
+
"""Stop filling this school's sign-in in until the user saves the account again."""
|
|
152
|
+
from . import config as cfg
|
|
153
|
+
|
|
154
|
+
current = cfg.load_config()
|
|
155
|
+
logins = dict(_logins(current))
|
|
156
|
+
entry = logins.get(entity_id)
|
|
157
|
+
if isinstance(entry, dict):
|
|
158
|
+
logins[entity_id] = {**entry, "enabled": False, "off": why}
|
|
159
|
+
current[CONFIG_KEY] = logins
|
|
160
|
+
cfg.save_config(current)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
# -- where and how often ----------------------------------------------------------------------
|
|
164
|
+
|
|
165
|
+
def may_fill(url: str, config: dict[str, Any], also: tuple[str, ...] = ()) -> bool:
|
|
166
|
+
"""An https page of the school's own: one of its login hosts as its federation lists them,
|
|
167
|
+
or under its own domains. Hosts merely passed through in a batch never count. ``also``: the
|
|
168
|
+
hosts Pro has for this school's login page on another domain of its own (Pro's ``login_hosts``,
|
|
169
|
+
found by its survey: a login system that sends to a login page on a second domain of the school's)."""
|
|
170
|
+
from .schools import lookup
|
|
171
|
+
|
|
172
|
+
parsed = urlparse(str(url or ""))
|
|
173
|
+
host = (parsed.hostname or "").lower()
|
|
174
|
+
if parsed.scheme != "https" or not host:
|
|
175
|
+
return False
|
|
176
|
+
if host in set(lookup.login_hosts(config)) or host in {str(h).lower() for h in also}:
|
|
177
|
+
return True
|
|
178
|
+
return any(host == domain or host.endswith("." + domain) for domain in lookup.domains(config))
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def pro_login_hosts(pro: Any, entity_id: str) -> tuple[str, ...]:
|
|
182
|
+
"""Pro's hosts for this school's login page on another domain of its own (``may_fill``'s ``also``);
|
|
183
|
+
none from a Pro without them."""
|
|
184
|
+
hosts = getattr(pro, "login_hosts", None)
|
|
185
|
+
try:
|
|
186
|
+
return tuple(str(h).strip().lower() for h in (hosts(entity_id) if callable(hosts) else ()) if str(h).strip())
|
|
187
|
+
except Exception:
|
|
188
|
+
return ()
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
# -- a login page whose certificate has expired or is not trusted ---------------------------------
|
|
192
|
+
# Some schools' login pages serve a certificate Chrome will not take (one ran out in 2022;
|
|
193
|
+
# others are issued by an authority Chrome does not trust): Chrome stops at its warning. For those
|
|
194
|
+
# Pro's survey has recorded the certificate the page serves; the warning is passed, and the account
|
|
195
|
+
# typed in, only when the page then has that very certificate (user, 2026-11-20: fill those in too).
|
|
196
|
+
# Its key never leaves the school, so another server cannot show it: the account goes to the school.
|
|
197
|
+
|
|
198
|
+
def pro_certificates(pro: Any, entity_id: str) -> dict[str, str]:
|
|
199
|
+
"""Pro's certificates for this school's login pages that Chrome will not take: host -> the
|
|
200
|
+
SHA-256 of the certificate (hex) its survey saw there; none from a Pro without them."""
|
|
201
|
+
found = getattr(pro, "certificates", None)
|
|
202
|
+
try:
|
|
203
|
+
pins = found(entity_id) if callable(found) else {}
|
|
204
|
+
return {str(h).strip().lower(): str(d).strip().lower() for h, d in dict(pins or {}).items() if str(h).strip() and str(d).strip()}
|
|
205
|
+
except Exception:
|
|
206
|
+
return {}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def page_certificate(page: Any, wait: float = 2.0) -> tuple[str, str]:
|
|
210
|
+
"""(the certificate error the page was let through with, "" for a certificate Chrome takes; the SHA-256
|
|
211
|
+
of the page's own certificate), as Chrome shows them for the page (DevTools' Security domain).
|
|
212
|
+
("?", "") when they could not be read: a browser that is not Chromium, a page gone."""
|
|
213
|
+
import base64
|
|
214
|
+
import hashlib
|
|
215
|
+
|
|
216
|
+
try:
|
|
217
|
+
session = page.context.new_cdp_session(page)
|
|
218
|
+
except Exception:
|
|
219
|
+
return "?", ""
|
|
220
|
+
seen: list[dict] = []
|
|
221
|
+
try:
|
|
222
|
+
session.on("Security.visibleSecurityStateChanged", lambda e: seen.append(dict(e.get("visibleSecurityState") or {})))
|
|
223
|
+
session.send("Security.enable") # the page's state comes at once
|
|
224
|
+
deadline = time.time() + wait
|
|
225
|
+
while not seen and time.time() < deadline:
|
|
226
|
+
page.wait_for_timeout(100)
|
|
227
|
+
except Exception:
|
|
228
|
+
return "?", ""
|
|
229
|
+
finally:
|
|
230
|
+
try:
|
|
231
|
+
session.detach()
|
|
232
|
+
except Exception:
|
|
233
|
+
pass
|
|
234
|
+
if not seen:
|
|
235
|
+
return "?", ""
|
|
236
|
+
state = seen[-1].get("certificateSecurityState") or {}
|
|
237
|
+
chain = state.get("certificate") or []
|
|
238
|
+
try:
|
|
239
|
+
digest = hashlib.sha256(base64.b64decode(chain[0])).hexdigest() if chain else ""
|
|
240
|
+
except ValueError:
|
|
241
|
+
digest = ""
|
|
242
|
+
return str(state.get("certificateNetworkError") or ""), digest
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def certificate_allows(host: str, error: str, digest: str, pins: dict[str, str]) -> bool:
|
|
246
|
+
"""Whether a page of ``host`` may get the account, by its certificate (``page_certificate``): one
|
|
247
|
+
Chrome takes, or the very one Pro has for that host. A host Pro has one for, whose certificate
|
|
248
|
+
could not be read, gets nothing; any other such page is as before (a browser without DevTools)."""
|
|
249
|
+
host = (host or "").lower()
|
|
250
|
+
if error == "?":
|
|
251
|
+
return host not in pins
|
|
252
|
+
return not error or bool(digest) and pins.get(host) == digest
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
#: Where Chrome's warning shows: its own error page, or about:blank for a page opened straight on the address.
|
|
256
|
+
WARNING_PAGES = ("chrome-error://", "about:blank")
|
|
257
|
+
#: Chrome's warning before a page whose certificate it will not take (its own error page).
|
|
258
|
+
_WARNING_JS = """(hosts) => {
|
|
259
|
+
const advanced = document.getElementById('details-button'), go = document.getElementById('proceed-link');
|
|
260
|
+
if (!advanced || !go) return '';
|
|
261
|
+
const text = (document.body && document.body.innerText || '').toLowerCase();
|
|
262
|
+
return hosts.find(h => text.includes(h)) || '';
|
|
263
|
+
}"""
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def warning_for(page: Any, hosts: tuple[str, ...], tries: int = 3) -> str:
|
|
267
|
+
"""The host, of ``hosts``, Chrome's certificate warning on this page is for; "" when it is not
|
|
268
|
+
such a warning (or one Chrome lets no one past: a host that insists on https, HSTS)."""
|
|
269
|
+
for _ in range(max(1, tries)):
|
|
270
|
+
# Chrome's own error page; a page opened straight on such an address still says about:blank.
|
|
271
|
+
if not hosts or not str(getattr(page, "url", "") or "").startswith(WARNING_PAGES):
|
|
272
|
+
return ""
|
|
273
|
+
try:
|
|
274
|
+
return str(page.evaluate(_WARNING_JS, [h.lower() for h in hosts]) or "")
|
|
275
|
+
except Exception: # the warning still being put up
|
|
276
|
+
try:
|
|
277
|
+
page.wait_for_timeout(500)
|
|
278
|
+
except Exception:
|
|
279
|
+
return ""
|
|
280
|
+
return ""
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def warning_certificate(host: str, error: str, digest: str, pins: dict[str, str]) -> bool:
|
|
284
|
+
"""Whether Chrome's warning for ``host`` is for the very certificate Pro has (``page_certificate`` read on
|
|
285
|
+
the warning: the certificate offered, with Chrome's error); never past one whose certificate went unread."""
|
|
286
|
+
return bool(error) and error != "?" and bool(digest) and pins.get((host or "").lower()) == digest
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def pass_warning(page: Any, host: str, wait: float = 20.0) -> bool:
|
|
290
|
+
"""Chrome's warning passed as a person would (Advanced, then Proceed): True once the page of
|
|
291
|
+
``host`` has loaded in its place."""
|
|
292
|
+
try:
|
|
293
|
+
page.evaluate("() => { document.getElementById('details-button').click(); document.getElementById('proceed-link').click(); }")
|
|
294
|
+
except Exception:
|
|
295
|
+
pass # the click goes on to the page at once, which may end the call: the page loading says whether it went
|
|
296
|
+
deadline = time.time() + wait
|
|
297
|
+
while time.time() < deadline:
|
|
298
|
+
if (urlparse(str(getattr(page, "url", "") or "")).hostname or "").lower() == host.lower():
|
|
299
|
+
try:
|
|
300
|
+
page.wait_for_load_state("domcontentloaded", timeout=max(1000, int((deadline - time.time()) * 1000)))
|
|
301
|
+
except Exception:
|
|
302
|
+
pass
|
|
303
|
+
return True
|
|
304
|
+
try:
|
|
305
|
+
page.wait_for_timeout(200)
|
|
306
|
+
except Exception:
|
|
307
|
+
return False
|
|
308
|
+
return False
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def _turns_file() -> Path:
|
|
312
|
+
from .entitlements import _data_dir
|
|
313
|
+
|
|
314
|
+
return _data_dir() / "school_sign_in.json"
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def take_turn(entity_id: str, now: float | None = None) -> bool:
|
|
318
|
+
"""Count one sign-in filled in for this school; False when this hour has had PER_HOUR."""
|
|
319
|
+
now = time.time() if now is None else now
|
|
320
|
+
path = _turns_file()
|
|
321
|
+
try:
|
|
322
|
+
data = json.loads(path.read_text(encoding="utf-8")) if path.exists() else {}
|
|
323
|
+
except (OSError, ValueError):
|
|
324
|
+
data = {}
|
|
325
|
+
if not isinstance(data, dict):
|
|
326
|
+
data = {}
|
|
327
|
+
times = [t for t in data.get(entity_id) or [] if isinstance(t, (int, float)) and now - HOUR < t <= now]
|
|
328
|
+
if len(times) >= PER_HOUR:
|
|
329
|
+
return False
|
|
330
|
+
data[entity_id] = [*times, now]
|
|
331
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
332
|
+
path.write_text(json.dumps(data), encoding="utf-8")
|
|
333
|
+
return True
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
# -- one sign-in --------------------------------------------------------------------------------
|
|
337
|
+
|
|
338
|
+
@dataclass
|
|
339
|
+
class Attempt:
|
|
340
|
+
"""What Pro's ``sign_in`` gets: the account, where it may be typed, and where to say what it did.
|
|
341
|
+
|
|
342
|
+
``event`` takes a state and a detail; it hides the account wherever a detail would carry it.
|
|
343
|
+
"""
|
|
344
|
+
|
|
345
|
+
username: str
|
|
346
|
+
password: str
|
|
347
|
+
allowed: Callable[[str], bool]
|
|
348
|
+
event: Callable[[str, str], None]
|
|
349
|
+
hidden: tuple[str, ...] = field(default=(), repr=False)
|
|
350
|
+
#: The school's entityID: its own rule, when Pro has one (schools/<federation>/<school>.py).
|
|
351
|
+
school: str = ""
|
|
352
|
+
#: Set by Pro on ``needs_user``: the kind of check the school's page asks the user for (image_code,
|
|
353
|
+
#: slider, click_select, sms_code, qr_scan, site_check, second_factor), for the note the user reads.
|
|
354
|
+
asks: str = ""
|
|
355
|
+
|
|
356
|
+
def __repr__(self) -> str: # never the account, not even in a traceback's locals
|
|
357
|
+
return "Attempt(<hidden>)"
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def hide(text: str, secrets: tuple[str, ...]) -> str:
|
|
361
|
+
"""``text`` with every secret replaced (an event's detail, defence in depth)."""
|
|
362
|
+
for secret in secrets:
|
|
363
|
+
if secret and len(secret) >= 3:
|
|
364
|
+
text = text.replace(secret, "***")
|
|
365
|
+
return text
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
#: How a sign-in went (Pro's ``sign_in``):
|
|
369
|
+
#: ``submitted`` the form was sent and the page moved on; ``rejected`` the school's page came back
|
|
370
|
+
#: asking again (a wrong password); ``needs_user`` a code, a captcha or a second factor;
|
|
371
|
+
#: ``no_form`` none found; ``unsafe_form`` more than one password field (changing a password);
|
|
372
|
+
#: ``not_allowed`` the form sits in a frame of another site; ``failed`` the page broke off.
|
|
373
|
+
OUTCOMES = ("submitted", "rejected", "needs_user", "no_form", "unsafe_form", "not_allowed", "failed")
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""The user's school: finding it by the name the user gave and saving it (``lookup``),
|
|
2
|
+
and the several schools saved, one of them the current one (``saved``).
|
|
3
|
+
|
|
4
|
+
Apart from the federations (``federations``: who a federation is and how publishers
|
|
5
|
+
name it), as the user set the layers on 2026-11-17. ``lookup`` reads the federations'
|
|
6
|
+
data and CARSI's member list (``federations.carsi``) to find a school.
|
|
7
|
+
"""
|
|
@@ -28,7 +28,7 @@ from pathlib import Path
|
|
|
28
28
|
from typing import Any, Iterable
|
|
29
29
|
from urllib.parse import quote, urlparse
|
|
30
30
|
|
|
31
|
-
from
|
|
31
|
+
from ..federations import Federation, all_federations, by_code, by_registration_authority, configured
|
|
32
32
|
|
|
33
33
|
SEAMLESSACCESS = "https://md.seamlessaccess.org/entities/"
|
|
34
34
|
METADATA_MAX_AGE_SEC = 7 * 24 * 3600
|
|
@@ -127,7 +127,7 @@ def entity_id(config: dict[str, Any], data_dir: Path) -> str:
|
|
|
127
127
|
saved = name(config)
|
|
128
128
|
if not saved:
|
|
129
129
|
return ""
|
|
130
|
-
from ..
|
|
130
|
+
from ..federations.carsi import CACHE_FILE, choose_school, parse_school_list
|
|
131
131
|
|
|
132
132
|
cache = Path(data_dir) / CACHE_FILE
|
|
133
133
|
if not cache.is_file():
|
|
@@ -326,7 +326,7 @@ def _matches(given: Iterable[str], listed_names: Iterable[str], scopes: Iterable
|
|
|
326
326
|
|
|
327
327
|
|
|
328
328
|
def _from_school_list(given: list[str], config: dict[str, Any], data_dir: Path, found: _Found, lookup: Lookup) -> None:
|
|
329
|
-
from ..
|
|
329
|
+
from ..federations.carsi import find_schools, load_school_list
|
|
330
330
|
|
|
331
331
|
try:
|
|
332
332
|
schools = load_school_list(config, data_dir)
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""Several schools saved, one of them the current one (user, 2026-11-17: "以后我可以有几个学校的话,
|
|
2
|
+
可以随时进行一个切换"). The current school stays in the config's own fields, which all the code
|
|
3
|
+
reads (``SCHOOL_FIELDS``); ``saved_schools`` keeps each saved school's copy of them. Switching
|
|
4
|
+
writes the chosen copy back into those fields. A download may use another saved school for
|
|
5
|
+
itself alone (``apply`` on that download's config, not saved). Nothing switches on its own: only
|
|
6
|
+
when the user says so (user, 2026-11-17)."""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
# What `setup --institution` saves of a school (schools/lookup.py `save`).
|
|
12
|
+
SCHOOL_FIELDS = ("school_name", "school_name_en", "school_entry_name", "idp_entity_id", "idp_login_hosts",
|
|
13
|
+
"idp_login_pages", "idp_domains", "publisher_institution_federation", "carsi_enabled")
|
|
14
|
+
SAVED_KEY = "saved_schools"
|
|
15
|
+
MAX_SAVED = 20
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def current(config: dict[str, Any]) -> dict[str, Any] | None:
|
|
19
|
+
"""The current school's fields; None when no school is set."""
|
|
20
|
+
if not str(config.get("school_name") or config.get("idp_entity_id") or "").strip():
|
|
21
|
+
return None
|
|
22
|
+
return {key: config.get(key) for key in SCHOOL_FIELDS}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def saved(config: dict[str, Any]) -> list[dict[str, Any]]:
|
|
26
|
+
"""The saved schools, each with at least its name; anything else in the list is left out."""
|
|
27
|
+
raw = config.get(SAVED_KEY)
|
|
28
|
+
if not isinstance(raw, list):
|
|
29
|
+
return []
|
|
30
|
+
return [{key: entry.get(key) for key in SCHOOL_FIELDS} for entry in raw
|
|
31
|
+
if isinstance(entry, dict) and str(entry.get("school_name") or "").strip()][:MAX_SAVED]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _same(one: dict[str, Any], other: dict[str, Any]) -> bool:
|
|
35
|
+
"""One school: the same entityID, else the same name."""
|
|
36
|
+
ids = [str(entry.get("idp_entity_id") or "").strip().lower() for entry in (one, other)]
|
|
37
|
+
if ids[0] and ids[1]:
|
|
38
|
+
return ids[0] == ids[1]
|
|
39
|
+
return str(one.get("school_name") or "").strip().casefold() == str(other.get("school_name") or "").strip().casefold()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def remember(config: dict[str, Any]) -> None:
|
|
43
|
+
"""The current school in the saved list (its copy brought up to date when already there)."""
|
|
44
|
+
school = current(config)
|
|
45
|
+
if school is None:
|
|
46
|
+
return
|
|
47
|
+
schools = saved(config)
|
|
48
|
+
for index, entry in enumerate(schools):
|
|
49
|
+
if _same(entry, school):
|
|
50
|
+
schools[index] = school
|
|
51
|
+
break
|
|
52
|
+
else:
|
|
53
|
+
schools.append(school)
|
|
54
|
+
config[SAVED_KEY] = schools[:MAX_SAVED]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _names(entry: dict[str, Any]) -> list[str]:
|
|
58
|
+
domains = entry.get("idp_domains") if isinstance(entry.get("idp_domains"), list) else []
|
|
59
|
+
return [str(value).strip() for value in (entry.get("school_name"), entry.get("school_name_en"),
|
|
60
|
+
entry.get("school_entry_name"), entry.get("idp_entity_id"), *domains)
|
|
61
|
+
if str(value or "").strip()]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def find(config: dict[str, Any], query: str) -> list[dict[str, Any]]:
|
|
65
|
+
"""The saved schools ``query`` names: by a whole name, English name, entityID or domain;
|
|
66
|
+
else those whose names contain it. The current school is among them."""
|
|
67
|
+
wanted = query.strip().casefold()
|
|
68
|
+
if not wanted:
|
|
69
|
+
return []
|
|
70
|
+
remember(config)
|
|
71
|
+
schools = saved(config)
|
|
72
|
+
exact = [entry for entry in schools if any(name.casefold() == wanted for name in _names(entry))]
|
|
73
|
+
return exact or [entry for entry in schools if any(wanted in name.casefold() for name in _names(entry))]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def apply(config: dict[str, Any], entry: dict[str, Any]) -> None:
|
|
77
|
+
"""``entry`` as the school of ``config`` (the current one once the config is saved)."""
|
|
78
|
+
for key in SCHOOL_FIELDS:
|
|
79
|
+
config[key] = entry.get(key)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def is_current(config: dict[str, Any], entry: dict[str, Any]) -> bool:
|
|
83
|
+
school = current(config)
|
|
84
|
+
return school is not None and _same(school, entry)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def summary(entry: dict[str, Any], config: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
88
|
+
"""What a listing says of a school: names, federation, entityID, whether current."""
|
|
89
|
+
out = {"name": entry.get("school_name") or "", "name_en": entry.get("school_name_en") or "",
|
|
90
|
+
"federation": entry.get("publisher_institution_federation") or "", "entity_id": entry.get("idp_entity_id") or ""}
|
|
91
|
+
if config is not None:
|
|
92
|
+
out["current"] = is_current(config, entry)
|
|
93
|
+
return out
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def use_for_download(config: dict[str, Any], query: str) -> str:
|
|
97
|
+
"""The saved school ``query`` names as ``config``'s school, for one download (the config is
|
|
98
|
+
not saved); "" when done, else why not: school_not_saved, school_ambiguous."""
|
|
99
|
+
matches = find(config, query)
|
|
100
|
+
if len(matches) != 1:
|
|
101
|
+
return "school_not_saved" if not matches else "school_ambiguous"
|
|
102
|
+
apply(config, matches[0])
|
|
103
|
+
return ""
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def forget(config: dict[str, Any], entry: dict[str, Any]) -> bool:
|
|
107
|
+
"""``entry`` out of the saved list; the current school stays (False)."""
|
|
108
|
+
if is_current(config, entry):
|
|
109
|
+
return False
|
|
110
|
+
config[SAVED_KEY] = [other for other in saved(config) if not _same(other, entry)]
|
|
111
|
+
return True
|
|
@@ -18,7 +18,6 @@ import asyncio
|
|
|
18
18
|
import json
|
|
19
19
|
import re
|
|
20
20
|
import time
|
|
21
|
-
from concurrent.futures import ThreadPoolExecutor
|
|
22
21
|
from functools import partial
|
|
23
22
|
from typing import Any, Literal
|
|
24
23
|
|
|
@@ -30,7 +29,7 @@ except ModuleNotFoundError: # mcp >= 2.0 renamed FastMCP to MCPServer
|
|
|
30
29
|
from .cache import cache_clear
|
|
31
30
|
from .config import load_config
|
|
32
31
|
from .orchestrator import download_institutional as download
|
|
33
|
-
from .browser.batch_session import BatchBrowser, active_batch
|
|
32
|
+
from .browser.batch_session import BatchBrowser, BatchThread, active_batch
|
|
34
33
|
|
|
35
34
|
SERVER_NAME = "paper-search-school"
|
|
36
35
|
Strategy = Literal["legal_only", "institutional_only"]
|
|
@@ -48,8 +47,9 @@ mcp_app = FastMCP(
|
|
|
48
47
|
)
|
|
49
48
|
|
|
50
49
|
_DOI_RE = re.compile(r"10\.\d{4,9}/[-._;()/:A-Z0-9]+", re.I)
|
|
51
|
-
_batch_worker = ThreadPoolExecutor(max_workers=1, thread_name_prefix="school-batch")
|
|
52
50
|
_batch_browser = BatchBrowser()
|
|
51
|
+
# Its tab answers between papers too (BatchThread, BatchBrowser.pump).
|
|
52
|
+
_batch_worker = BatchThread(_batch_browser.pump)
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
def _with_batch_browser(batch_id: str, operation) -> str:
|
|
@@ -82,6 +82,8 @@ def school_download(
|
|
|
82
82
|
user_wait: str | None = None,
|
|
83
83
|
diagnostics_dir: str | None = None,
|
|
84
84
|
title: str | None = None,
|
|
85
|
+
fulltext: str | None = None,
|
|
86
|
+
school: str | None = None,
|
|
85
87
|
) -> str:
|
|
86
88
|
"""Synchronous download entry; ``download`` is module-level so tests can stub it.
|
|
87
89
|
|
|
@@ -93,7 +95,11 @@ def school_download(
|
|
|
93
95
|
batch = progress_reporter.BatchContext.from_args(
|
|
94
96
|
batch_id, batch_index, batch_total, batch_done, batch_succeeded, batch_failed)
|
|
95
97
|
content = {"with": "both", "only": "supplements"}.get(supplements or "", "main")
|
|
96
|
-
with
|
|
98
|
+
# A visit for the page alone is the Markdown's; one with the PDF or the files, theirs and it.
|
|
99
|
+
if fulltext == "only" and not supplements:
|
|
100
|
+
content = "markdown"
|
|
101
|
+
with progress_reporter.tracked_download(current, output_dir, batch, content=content,
|
|
102
|
+
markdown=fulltext in ("with", "only")) as outcome:
|
|
97
103
|
kwargs = {"supplements": supplements} if supplements in ("with", "only") else {}
|
|
98
104
|
if user_wait == "short":
|
|
99
105
|
kwargs["user_wait"] = user_wait
|
|
@@ -101,6 +107,10 @@ def school_download(
|
|
|
101
107
|
kwargs["diagnostics_dir"] = diagnostics_dir
|
|
102
108
|
if title:
|
|
103
109
|
kwargs["title"] = title
|
|
110
|
+
if fulltext in ("with", "only"):
|
|
111
|
+
kwargs["fulltext"] = fulltext
|
|
112
|
+
if school and school.strip():
|
|
113
|
+
kwargs["school"] = school.strip()
|
|
104
114
|
from .entitlements import batch_stop_requested
|
|
105
115
|
|
|
106
116
|
if batch_stop_requested():
|
|
@@ -124,9 +134,8 @@ def school_download(
|
|
|
124
134
|
outcome["failure_phase"] = "网站已阻止当前访问,未取得 PDF"
|
|
125
135
|
if result.get("error_type") == "rate_limited":
|
|
126
136
|
until = time.time() + int(result.get("retry_after_sec") or 0)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
f"{result.get('publisher')} 一小时内已打开 {result.get('limit')} 篇(每小时上限),{resume} 继续这一篇")
|
|
137
|
+
outcome["paused"] = outcome["failure_phase"] = progress_reporter.hourly_phase(
|
|
138
|
+
str(result.get("publisher") or ""), result.get("limit"), until)
|
|
130
139
|
# The window says so until then, beside the other lane's lines (2026-11-12).
|
|
131
140
|
outcome["hourly_wait"] = {"publisher": str(result.get("publisher") or ""),
|
|
132
141
|
"limit": result.get("limit"), "until": until,
|
|
@@ -159,6 +168,8 @@ async def _school_download_with_progress(
|
|
|
159
168
|
diagnostics_dir: str | None = None,
|
|
160
169
|
keep_browser: bool = False,
|
|
161
170
|
title: str | None = None,
|
|
171
|
+
fulltext: Literal["with", "only"] | None = None,
|
|
172
|
+
school: str | None = None,
|
|
162
173
|
ctx: Context = None,
|
|
163
174
|
) -> str:
|
|
164
175
|
"""Download one paper by DOI through institutional access only.
|
|
@@ -182,6 +193,18 @@ async def _school_download_with_progress(
|
|
|
182
193
|
it when the article page gives no title of its own (citation_title): Science on Atypon
|
|
183
194
|
gives none, and its older PDFs print the DOI only on the last page.
|
|
184
195
|
|
|
196
|
+
fulltext: "with" also saves the article's full-text page and its figure images while the
|
|
197
|
+
browser is on the article for the PDF (no extra page load), for publishers whose page
|
|
198
|
+
PaperSearch converts to Markdown: ``<output_dir>/<DOI>_fulltext_page/`` (article.html,
|
|
199
|
+
images/), given in the result's ``fulltext_page`` (file, url, images). Kept when the PDF fails
|
|
200
|
+
for another reason than entitlement but the page showed the full text. "only" opens the
|
|
201
|
+
article for its page alone, no PDF (the main text came from elsewhere); with
|
|
202
|
+
``supplements="only"`` the page is read on that visit.
|
|
203
|
+
|
|
204
|
+
school: another saved school (`paper-search-school schools`) for this download alone, as the
|
|
205
|
+
user asked; the configured school is not changed. Not saved: the result's error_type is
|
|
206
|
+
school_not_saved (or school_ambiguous).
|
|
207
|
+
|
|
185
208
|
user_wait: "short" when the user seems away (an earlier article of the batch waited on them
|
|
186
209
|
until its time was up): each wait on the user (school login, human verification) lasts at
|
|
187
210
|
most 60 s, unless someone starts typing on the login page.
|
|
@@ -192,7 +215,7 @@ async def _school_download_with_progress(
|
|
|
192
215
|
use_vpnsci, bibtex, strategy, batch_id=batch_id, batch_index=batch_index,
|
|
193
216
|
batch_total=batch_total, batch_done=batch_done, batch_succeeded=batch_succeeded,
|
|
194
217
|
batch_failed=batch_failed, supplements=supplements, user_wait=user_wait,
|
|
195
|
-
diagnostics_dir=diagnostics_dir, title=title)
|
|
218
|
+
diagnostics_dir=diagnostics_dir, title=title, fulltext=fulltext, school=school)
|
|
196
219
|
if keep_browser and batch_id:
|
|
197
220
|
return await run_with_progress(ctx, identifier, partial(_with_batch_browser, batch_id, operation),
|
|
198
221
|
executor=_batch_worker)
|
|
@@ -216,6 +239,26 @@ async def school_keep_session() -> str:
|
|
|
216
239
|
return json.dumps(result)
|
|
217
240
|
|
|
218
241
|
|
|
242
|
+
@mcp_app.tool()
|
|
243
|
+
def school_hourly_wait(publisher: str) -> str:
|
|
244
|
+
"""While a batch waits for the hourly limit the user set: the seconds until ``publisher`` (as
|
|
245
|
+
the rate_limited answer named it) may open another article. With the switch beside the limit
|
|
246
|
+
on (马上生效, ``publisher_hourly_limit_now``), under the limit as it is now: one raised in the
|
|
247
|
+
settings window, or set to 0 (none), lets the batch go on at once, and one changed and still
|
|
248
|
+
reached shows in the progress window; off, the wait goes on until the hour is over
|
|
249
|
+
(2026-11-19). Opens no browser. Answers {"wait_sec": n, "limit": n}."""
|
|
250
|
+
from . import progress_reporter, rate_limit, user_settings
|
|
251
|
+
|
|
252
|
+
config = load_config()
|
|
253
|
+
limit = int(config.get("publisher_hourly_limit", rate_limit.DEFAULT_LIMIT) or 0)
|
|
254
|
+
if config.get(user_settings.HOURLY_NOW_KEY) is not True:
|
|
255
|
+
return json.dumps({"wait_sec": rate_limit.hour_left(publisher), "limit": limit})
|
|
256
|
+
wait = rate_limit.wait_seconds(publisher, limit)
|
|
257
|
+
if wait:
|
|
258
|
+
progress_reporter.hourly_limit_now(publisher, limit, time.time() + wait)
|
|
259
|
+
return json.dumps({"wait_sec": wait, "limit": limit})
|
|
260
|
+
|
|
261
|
+
|
|
219
262
|
@mcp_app.tool()
|
|
220
263
|
def school_batch_progress(
|
|
221
264
|
batch_id: str,
|
|
@@ -275,7 +318,8 @@ def school_batch_papers(batch_id: str, folder: str, papers: list[dict[str, Any]]
|
|
|
275
318
|
doi, title, journal, state ("open": open access not checked yet, "school": waiting
|
|
276
319
|
for or in the institutional download, "ok", "failed"); a saved one adds via
|
|
277
320
|
(开放下载 or 机构下载), detail (出版社 API, Sci-Hub, 预印本) and path (the PDF,
|
|
278
|
-
absolute); a failed one cls (no_access,
|
|
321
|
+
absolute); a failed one cls (no_access, user_side, school_side, publisher_or_network,
|
|
322
|
+
article_or_site, unsupported, unexplained)
|
|
279
323
|
and reason}]. folder: the batch's download folder (absolute); the window opens
|
|
280
324
|
a PDF only from inside it. Never touches the running download's progress.
|
|
281
325
|
"""
|