Spaces:
Runtime error
Runtime error
File size: 1,169 Bytes
91d75c7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | """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()
|