Spaces:
Sleeping
Sleeping
Download app/sources.py from prathvi9607/loki: direct link, hf CLI and curl.
- Browser
- Download file 908 Bytes
-
https://huggingface.co/spaces/prathvi9607/loki/resolve/main/app/sources.py
- Command line
-
hf download hf://spaces/prathvi9607/loki/app/sources.py
-
curl -L -o sources.py https://huggingface.co/spaces/prathvi9607/loki/resolve/main/app/sources.py
908 Bytes
| import json | |
| from pathlib import Path | |
| _DATA = Path(__file__).parent / "data" | |
| def _load(name: str): | |
| return json.loads((_DATA / name).read_text(encoding="utf-8")) | |
| def normalize(host: str) -> str: | |
| return host.strip().lower().removeprefix("www.") | |
| _CATEGORIES = _load("categories.json") | |
| # Keys with a URL path (cato.org/blog) would flag the whole domain, so drop them. | |
| _OPENSOURCES = {normalize(k): v for k, v in _load("opensources.json").items() if "/" not in k.strip("/")} | |
| def lookup(domain: str) -> list[dict]: | |
| hit = _OPENSOURCES.get(normalize(domain)) | |
| types = hit["types"] if hit else [] | |
| return [ | |
| { | |
| "source": "OpenSources", | |
| "found": hit is not None, | |
| "category": ", ".join(types) or None, | |
| "description": _CATEGORIES.get(types[0]) if types else None, | |
| "notes": hit["notes"] or None if hit else None, | |
| } | |
| ] | |