#!/usr/bin/env python3 # Job #609: fetch every return on the board and index which ones touch the owning # notes / ids of rows 38-52. Reveals the return that supersedes a ledger block. import json, os, re, urllib.request, urllib.error B = "https://solveathome.org/projects/twin-primes" H = {"Authorization": "Bearer " + os.environ["SAH"], "X-Model": "deepseek-v4.1-flash", "X-Session": "266d9746eb765060ee1faaa9", "Accept": "application/json"} KEYS = { "Q-rec-cheapest-0830": r"rec-cheapest|Q-rec-cheapest|0830-rec-cheapest", "Q-recon-0904-sifting-limit-floor": r"sifting-limit|Q-recon-0904-sifting", "Q-rho-maximal-law": r"rho-maximal-law|rho-exact-z31|Q-rho-maximal-law", "Q-rho-sup-z41-0830": r"rho-sup-z41|Q-rho-sup-z41", "Q-rml-proof-0829n": r"ml-proof|Q-rml-proof|0829n-rml", "Q-fekete-1d-defect47": r"fekete|Q-fekete", "Q-g2-falls-decision-rule": r"decision-rule|T3prep|Q-g2-falls", "Q-hsub-reductions": r"hsub|Q-hsub", "Q-xchannel-at23": r"xchannel-at23|Q-xchannel-at23", "Q-xchannel-closedform": r"xchan-at29|xchannel-closedform|xchan-closedform|Q-xchannel-closedform|4S2", "Q-xchannel-offset": r"item-x-offset|Q-xchannel-offset", "Q-at43-bigint-0830": r"at43-bigint|Q-at43-bigint|0830-at43", "Q-comb-discrepancy": r"comb-discrepancy|Q-comb-discrepancy", "Q-comb-tail-0830": r"comb-tail|Q-comb-tail", "Q-c2prime-drift": r"c2drift|c2prime-drift|c2prime-refit|Q-c2prime-drift", } PAT = {k: re.compile(v, re.I) for k, v in KEYS.items()} N = int(os.environ.get("N", "240")) out, fails = [], [] for i in range(1, N + 1): rq = urllib.request.Request(B + "/return/%d" % i, headers=H) try: d = json.loads(urllib.request.urlopen(rq, timeout=25).read().decode("utf-8", "replace")) except urllib.error.HTTPError as e: fails.append((i, e.code)); continue except Exception as e: fails.append((i, str(e)[:50])); continue rep = d.get("report_md") or "" title = d.get("title") or "" hits = sorted(k for k, p in PAT.items() if p.search(rep) or p.search(title)) out.append(dict(id=i, type=d.get("type"), status=d.get("status"), handle=d.get("handle"), model=d.get("model"), created=d.get("created_at"), rung=d.get("final_rung"), job=d.get("job_id"), title=title[:170], reviews=[(rv.get("verdict"), rv.get("reviewer"), rv.get("reason_class")) for rv in (d.get("reviews") or [])], hits=hits, chars=len(rep))) json.dump(out, open("job609/returns-sweep.json", "w", encoding="utf-8"), indent=1, ensure_ascii=False) print("fetched:", len(out), " failed:", fails) print() for r in out: if r["hits"]: rv = (" reviews=" + str(r["reviews"])) if r["reviews"] else "" print(f'#{r["id"]:<4} {r["type"]:<9} {r["status"]:<10} {r["created"]} @{r["handle"]} rung={r["rung"]}{rv}') print(f' hits={r["hits"]}') print(f' {r["title"][:165]}')