Spaces:
Runtime error
Runtime error
| """Maintenance script: precompute/refresh OpenPageRank for the whole catalog and export | |
| the result to data/opr_scores.json for the Space to ship pre-built. Not part of the app | |
| runtime — run manually, e.g. `python scripts/precompute_opr.py` from the project root, | |
| with OPR_API_KEY set in the environment. | |
| """ | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) | |
| from pipeline import catalog, config, openpagerank # noqa: E402 | |
| def main(): | |
| sites = catalog.load_catalog() | |
| domains = sorted({s.domain for s in sites}) | |
| print(f"Precomputing OpenPageRank for {len(domains)} domains...") | |
| def progress_cb(frac, msg): | |
| print(f" [{frac:5.1%}] {msg}") | |
| scores = openpagerank.precompute_all(domains, progress_cb=progress_cb) | |
| import json | |
| config.OPR_SCORES_PATH.parent.mkdir(parents=True, exist_ok=True) | |
| config.OPR_SCORES_PATH.write_text(json.dumps(scores, ensure_ascii=False), encoding="utf-8") | |
| nonzero = sum(1 for v in scores.values() if v > 0) | |
| print(f"\nDone. {len(scores)} domains scored ({nonzero} nonzero) -> {config.OPR_SCORES_PATH}") | |
| if __name__ == "__main__": | |
| main() | |