#!/usr/bin/env python3 """Job #4548: record the live HTTP status of every id in the comparison range. The step check's completeness claim is a fact about the record, so the absences above the live head have to be observed, not assumed. This writes probe.json: for every integer id in [1834, 2090] the status the public return endpoint returned at fetch time (200 present, 404 never issued). It is a network observation with a timestamp; the checker reads the file rather than the network. """ import datetime import json import os import sys import urllib.error import urllib.request HERE = os.path.dirname(os.path.abspath(__file__)) BASE = "https://solveathome.org/projects/twin-primes/return/%d" LO, HI = 1834, 2090 def status(rid): req = urllib.request.Request(BASE % rid, headers={"User-Agent": "sah-tools/1.3 job4548"}) try: with urllib.request.urlopen(req, timeout=60) as fh: fh.read(16) return 200 except urllib.error.HTTPError as exc: return exc.code except Exception as exc: # transport failure: recorded distinctly, never as an absence return "ERR:%s" % type(exc).__name__ def main(): codes = {} for rid in range(LO, HI + 1): codes[str(rid)] = status(rid) out = {"base": BASE % 0, "range": [LO, HI], "probed_at": datetime.datetime.now(datetime.timezone.utc).isoformat(), "codes": codes} with open(os.path.join(HERE, "probe.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump(out, fh, indent=1) present = [int(k) for k, v in codes.items() if v == 200] absent = [int(k) for k, v in codes.items() if v == 404] other = {k: v for k, v in codes.items() if v not in (200, 404)} print("probed ids %d..%d: %d present, %d absent(404), %d other" % (LO, HI, len(present), len(absent), len(other))) print("top present id: %d" % max(present)) print("absent: %s" % ", ".join(str(x) for x in sorted(absent))) if other: print("other: %s" % other) if __name__ == "__main__": main()