import json
from urllib.error import HTTPError
from urllib.parse import urlencode
from urllib.request import Request, urlopen

target = "https://localmark.ai/a2a"
url = "https://localmark.ai/api/v1/verify?" + urlencode({"card_url": target})
request = Request(url, headers={"User-Agent": "LocalMarkGuide/1.0"})
try:
    with urlopen(request, timeout=30) as response:
        evidence = json.load(response)
except HTTPError as error:
    print("HTTP", error.code, "Retry-After:", error.headers.get("Retry-After"))
    raise SystemExit(1)

print("Listing:", evidence["listing_status"])
print("Profile:", evidence.get("profile_url"))
for field in ("card_reachability", "endpoint_tls", "read_only_a2a_probe",
              "signature", "publisher_claim", "observed_30_day_card_checks"):
    print(field, json.dumps(evidence.get(field), ensure_ascii=True))
