46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""One-shot Tourism vintage collector."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
from typing import Any, Callable, Iterable
|
|
|
|
from .bot_tourism import BotTourismSource
|
|
from .vintages import VintageStore
|
|
|
|
|
|
def _default_exposures() -> list[dict[str, Any]]:
|
|
fixture_path = Path(__file__).resolve().parents[1] / "fixtures" / "tourism_snapshot.json"
|
|
snapshot = json.loads(fixture_path.read_text(encoding="utf-8"))
|
|
return [dict(item) for item in snapshot.get("exposures", [])]
|
|
|
|
|
|
def collect_bot_vintage(
|
|
root: Path | str,
|
|
*,
|
|
opener: Any | None = None,
|
|
clock: Callable[[], datetime] | None = None,
|
|
timeout: float = 30.0,
|
|
exposures: Iterable[dict[str, Any]] | None = None,
|
|
) -> dict[str, Any]:
|
|
"""Fetch one BOT vintage and register it in the immutable manifest."""
|
|
|
|
store = VintageStore(root)
|
|
source = BotTourismSource(
|
|
opener=opener,
|
|
clock=clock,
|
|
timeout=timeout,
|
|
vintage_store=store,
|
|
)
|
|
snapshot = source.fetch(exposures=_default_exposures() if exposures is None else exposures)
|
|
vintage_id = snapshot["source"]["vintage_id"]
|
|
entry = store.load_manifest()["vintages"][vintage_id]
|
|
return {
|
|
"snapshot": snapshot,
|
|
"manifest_path": str(store.manifest_path),
|
|
"seen_count": entry["seen_count"],
|
|
"revision_status": entry["revision_status"],
|
|
}
|