from datetime import datetime, timezone import pyarrow as pa from govdata.belastingdienst import extract from govdata.belastingdienst.index import Page, fetch_index from govdata.common.http import Fetcher S = pa.string() PAGES = pa.schema( [("url", S), ("title", S), ("topic", S), ("language", S), ("audience", S), ("lastmod", S), ("text", S)] ) class Belastingdienst: name = "belastingdienst" repo_id = "ethux/belastingdienst-dataset" n_shards = 4 key_col = "url" mod_col = "lastmod" shard_col = "url" raw_schema = pa.schema([("url", S), ("lastmod", S), ("fetched_at", S), ("html", S)]) configs = {"pages": PAGES} rate = 2.0 robots_exempt = frozenset() legacy = ("belastingdienst.csv", "data/legacy/belastingdienst.csv") def index(self, fetcher: Fetcher, limit: int | None) -> dict[str, Page]: return fetch_index(fetcher, limit) def modified(self, rec: Page) -> str: return rec.lastmod def fetch(self, fetcher: Fetcher, key: str, rec: Page) -> dict: r = fetcher.get(key) return { "url": key, "lastmod": rec.lastmod, "fetched_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"), "html": r.text, } def build(self, raw: pa.Table, index: dict[str, Page], run_date: str) -> dict[str, list[dict]]: pages = [] for row in raw.to_pylist(): page = extract.extract_page(row["html"], row["url"]) if page is None: continue topic, language, audience = extract.classify(row["url"]) pages.append( { "url": row["url"], "title": page["title"], "topic": topic, "language": language, "audience": audience, "lastmod": row["lastmod"], "text": page["text"], } ) return {"pages": pages} SOURCE = Belastingdienst()