#!/usr/bin/env python3 """Dry-run normalized match ingestion from a JSON file. This script exercises the provider-agnostic ingestion path without requiring a live data vendor or database adapter. Production deployments can replace the in-memory repository with a SQLAlchemy repository that implements ``MatchSnapshotRepository``. """ from __future__ import annotations import argparse import json from pathlib import Path import sys from fan_passport.match_ingestion import ( InMemoryMatchSnapshotRepository, JSONFileMatchProvider, MatchIngestionEngine, MatchIngestionError, ) def build_parser() -> argparse.ArgumentParser: parser = argparse.ArgumentParser(description="Validate and dry-run match data ingestion from JSON.") parser.add_argument("json_path", type=Path, help="Path to a JSON list/object containing normalized matches.") parser.add_argument( "--provider", default="local-json", help="Provider name to assign to snapshots that do not include one.", ) parser.add_argument( "--strict", action="store_true", help="Fail immediately on the first invalid snapshot instead of returning a report.", ) return parser def main() -> int: args = build_parser().parse_args() provider = JSONFileMatchProvider(args.json_path, provider_name=args.provider) engine = MatchIngestionEngine(InMemoryMatchSnapshotRepository()) try: report = engine.ingest(provider, strict=args.strict) except (OSError, MatchIngestionError, ValueError) as exc: print(f"match ingestion failed: {exc}", file=sys.stderr) return 1 print(json.dumps(report.to_dict(), indent=2, sort_keys=True)) return 0 if report.successful else 2 if __name__ == "__main__": raise SystemExit(main())