#!/usr/bin/env python """Phase 0: authenticated probe of FinData OS — contract reconciliation, no raw data, no credentials printed.""" from __future__ import annotations import json import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) from wp39.api_client import FinDataClient # noqa: E402 from wp39.catalog import probe # noqa: E402 from wp39.pipeline import Paths, get_logger, load_config # noqa: E402 from wp39.provenance import git_sha, now_iso, write_json # noqa: E402 def main() -> int: P = Paths.default() log = get_logger("00_probe", P.logs / "00_probe.log") contract = load_config("data_contract") client = FinDataClient(log_path=P.logs / "api_calls.jsonl") rep = probe(client, contract) rep["probed_at"], rep["code_sha"] = now_iso(), git_sha(P.root) # spot-check fundamentals + export schema on one well-known entity, counts only f = client.fundamentals("frd:AAPL", period_type="q", limit=20000) rep["aapl_quarterly_facts"] = len(f.get("data", [])) rep["aapl_metrics"] = sorted({r["metric"] for r in f.get("data", [])}) rep["pit_policy"] = f.get("meta", {}).get("pit_policy") periods = client.fundamentals_periods("frd:AAPL") rep["aapl_periods"] = len(periods) rep["aapl_first_filing"] = min(p["filing_date"] for p in periods if p.get("filing_date")) write_json(P.logs / "phase0_probe.json", rep) log.info("health=%s datasets=%d schema_ok=%s earnings_route=%s", rep["health_status"], rep["n_datasets"], rep["bars_fields_ok"], rep["has_earnings_route"]) for k, v in rep["required_datasets"].items(): log.info("dataset %s: %s", k, v) print(json.dumps({k: rep[k] for k in ("health_status", "n_datasets", "bars_fields_ok", "has_earnings_route", "aapl_quarterly_facts", "aapl_periods", "lake_free_gb")}, indent=1)) return 0 if __name__ == "__main__": raise SystemExit(main())