"""One-shot helper to (re)download the bundled Arabic font. Run if `src/lib/pdf_export/fonts/NotoNaskhArabic-Regular.ttf` is missing (e.g. fresh checkout that excluded it from git, or you wiped it). python -m src.lib.pdf_export.fetch_font Pinned to a notofonts.github.io tree on jsdelivr — same upstream source as Google Fonts, but a stable filename layout and no auth. """ from __future__ import annotations import hashlib import sys import urllib.request from pathlib import Path URL = ( "https://cdn.jsdelivr.net/gh/notofonts/notofonts.github.io@main/" "fonts/NotoNaskhArabic/full/ttf/NotoNaskhArabic-Regular.ttf" ) EXPECTED_SIZE = 291980 # bytes; sanity check, not a hard pin OUT = Path(__file__).resolve().parent / "fonts" / "NotoNaskhArabic-Regular.ttf" def main() -> int: OUT.parent.mkdir(parents=True, exist_ok=True) print(f"Fetching {URL}") req = urllib.request.Request(URL, headers={"User-Agent": "patristic-arabic-library/0.1"}) with urllib.request.urlopen(req, timeout=30) as r: data = r.read() print(f" {len(data):,} bytes SHA-256={hashlib.sha256(data).hexdigest()[:16]}…") if abs(len(data) - EXPECTED_SIZE) > 50_000: print( f"WARN: size {len(data):,} drifted from expected {EXPECTED_SIZE:,}. " f"The upstream may have changed; verify before relying on it." ) OUT.write_bytes(data) print(f"Wrote {OUT}") return 0 if __name__ == "__main__": raise SystemExit(main())