"""Fetch the two sources the citation screen still cannot resolve, and prove the fetch is current. Two edges on route 27's comparison surface point at artifacts not yet held: * #637's `L-TABLE-31.md` prints a second row labelled `L(T_29,p), filed #627`, and #645's level-29 stage compares against a `cited_row`; both cite return #627, which no previous assignment fetched. * route 27's own prose cites "#161's 1,307 measured entries" and "#161's diagonal ... at folds 7..31". #161 attached no files (`files: []`), so the only artifact that can state those values is the return body itself -- fetched here LIVE and hashed, so the resolution rests on what the server serves now, not on a copy made by an earlier assignment. Every response is persisted beside the request that produced it, exactly as the earlier fetchers do. """ import hashlib import json import os import sys TOOLS = os.path.join(os.environ["LOCALAPPDATA"], "solveathome", "tools", "v1") sys.path.insert(0, TOOLS) import sahtool # noqa: E402 (shared tool) import sahdated # noqa: E402 (shared tool) HERE = os.path.dirname(os.path.abspath(__file__)) RUN = os.path.dirname(HERE) OPS = os.path.join(RUN, "ops") RAW = os.path.join(HERE, "raw") BASE = "https://solveathome.org" os.makedirs(RAW, exist_ok=True) def tok(): return sahtool.token_from(type("A", (), {"token_file": None, "state": RUN})()) def get(path, name): code, text = sahtool.http("GET", BASE + path, token=tok(), headers={"Accept": "application/json"}) body_bytes = text.encode("utf-8") if isinstance(text, str) else text rec = {"op": "get", "path": path, "at": sahtool.now_iso(), "code": code, "sha256": hashlib.sha256(body_bytes).hexdigest(), "bytes": len(body_bytes)} rec.update({k: v for k, v in sahtool.transport_note(code, text).items()}) try: body = json.loads(text) except Exception: # noqa: BLE001 body = {"raw": text[:4000]} sahtool.write_json_atomic(os.path.join(OPS, "get-%s.json" % name), {"request": rec, "body": body}) sahtool.write_json_atomic(os.path.join(RAW, "%s.served.json" % name), {"fetched_at": sahtool.now_iso(), "path": path, "http": code, "sha256": rec["sha256"], "body": body}) print("%-14s HTTP %s %8d bytes sha %s" % (name, code, len(body_bytes), rec["sha256"][:16])) return body, rec if __name__ == "__main__": index = [] # 1. the record that the two citing artifacts name b627, r627 = get("/projects/twin-primes/return/627", "return627") body = b627.get("body", b627) files = body.get("files") or [] print(" #627 files:", [(f.get("name"), (f.get("sha256") or "")[:12]) for f in files]) index.append({"return": 627, "record_sha256": r627["sha256"], "files": len(files)}) for f in files: sha, name = f.get("sha256"), f.get("name") or "unnamed" if not sha: continue code, text = sahtool.http("GET", BASE + "/files/" + sha, token=tok(), headers={"Accept": "*/*"}) raw = text.encode("utf-8") if isinstance(text, str) else text got = hashlib.sha256(raw).hexdigest() out = os.path.join(RAW, "627-%s" % name) with open(out, "wb") as fh: fh.write(raw) index.append({"return": 627, "name": name, "sha256": sha, "http": code, "bytes": len(raw), "sha_matches_address": got == sha}) print(" files/%-10s %-26s HTTP %s %8d B %s" % (sha[:10], name, code, len(raw), "MATCH" if got == sha else "MISMATCH")) # 2. the return whose own body carries the route's cited 1,307 and diagonal b161, r161 = get("/projects/twin-primes/return/161", "return161") index.append({"return": 161, "record_sha256": r161["sha256"], "live": True}) sahdated.write(os.path.join(HERE, "fetched-627-161.json"), {"fetched": index, "why": ("the two sources still unresolved on route 27's comparison surface: the " "artifact #637 and #645 cite as `filed #627`, and a live copy of the return " "body that carries the route's cited 1,307 and its diagonal")}, source="citation-screen sources fetched live by the job-2970 screen") print("\nwrote fetched-627-161.json (%d entries)" % len(index))