"""Printed only, moves no verdict. The Archive refused 53 of 73 lookups in probe.py's run (connection errors
at 1.5 s apart). This asks again, one at a time and slower, using probe.py's own first_capture, and writes
domain -> first capture. Run: python -B captures.py ~/data/agent-cards/door.json out.json"""
import json
import sys
import time

import probe

rows = json.load(open(sys.argv[1]))["rows"]
out = {}
for r in rows:
    got = r["first_capture"]
    if got is None or not str(got).startswith("err:"):
        out[r["domain"]] = {"first": got, "source": "probe"}
        continue
    for wait in (8, 45, 120):
        time.sleep(wait)
        got = probe.first_capture(r["domain"], r["final"])
        if not str(got).startswith("err:"):
            break
    out[r["domain"]] = {"first": got, "source": "captures"}
    json.dump(out, open(sys.argv[2], "w"), indent=1)
json.dump(out, open(sys.argv[2], "w"), indent=1)
