Spaces:
Running on Zero
Running on Zero
Download scripts/fetch_sample_news.py from YuraBodnar/ChokePointAI: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/YuraBodnar/ChokePointAI/resolve/main/scripts/fetch_sample_news.py
- Command line
-
hf download hf://spaces/YuraBodnar/ChokePointAI/scripts/fetch_sample_news.py
-
curl -L -o fetch_sample_news.py https://huggingface.co/spaces/YuraBodnar/ChokePointAI/resolve/main/scripts/fetch_sample_news.py
1.04 kB
| import logging | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT / "src")) | |
| import httpx # noqa: E402 | |
| from chokepoint.ingestion.gdelt import DEFAULT_QUERY, fetch_gdelt # noqa: E402 | |
| from chokepoint.ingestion.normalize import gdelt_article_to_raw_document # noqa: E402 | |
| from chokepoint.ingestion.store import append_documents # noqa: E402 | |
| logging.basicConfig(level=logging.INFO, format="%(levelname)s %(message)s") | |
| logger = logging.getLogger(__name__) | |
| def main() -> int: | |
| try: | |
| articles = fetch_gdelt(DEFAULT_QUERY) | |
| except (httpx.HTTPError, httpx.TimeoutException) as error: | |
| logger.error("GDELT fetch failed: %s", error) | |
| return 1 | |
| documents = [ | |
| document | |
| for article in articles | |
| if (document := gdelt_article_to_raw_document(article)) is not None | |
| ] | |
| written = append_documents(documents, ROOT / "data/raw") | |
| print(f"new_documents={written}") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |