"""Retrieve the dated evidence set. Never execute downloaded source code."""
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime, timezone
from pathlib import Path
import hashlib, json, subprocess
root=Path(__file__).resolve().parents[1]
mit="https://math.mit.edu/~drew/grh/"
repo="https://raw.githubusercontent.com/leanprover-community/riemann-hypothesis/40e56bab026552e089d7afcfeff08d2defb9c005/"
sources={
 "riemann-1859.pdf":"https://www.claymath.org/library/historical/riemann/german/Zeta.pdf",
 "reading-guide.tex":"https://www.math.uwaterloo.ca/~mrubinst/alpoge_claude_grh/zeta-paper_v2.tex",
 "announcement.pdf":"https://alpo.ge/remark.pdf",
 "lean-community.html":"https://leanprover-community.github.io/blog/posts/riemann-hypothesis/",
 "mit.html":mit, "clay.html":"https://www.claymath.org/millennium/riemann-hypothesis/",
 "waterloo.html":"https://www.math.uwaterloo.ca/~mrubinst/alpoge_claude_grh/",
 "dlmf.html":"https://dlmf.nist.gov/25.10",
 "lmfdb.txt":"https://www.lmfdb.org/zeros/zeta/list?N=1&limit=100",
 "MainTheoremsAll.lean":repo+"src/Supplements/Kernels/MainTheoremsAll.lean",
 "MainTheoremsCritical.lean":repo+"src/Supplements/Kernels/MainTheoremsCritical.lean",
 "CorGKOf.lean":repo+"src/Development/AutomorphicArithmetic/AutomorphicVarieties/SmallClassNumbers/CorGKOf.lean",
 "Main.lean":repo+"src/Main.lean","Statements.lean":repo+"src/Statements.lean",
 "lean-toolchain":repo+"lean-toolchain","lake-manifest.json":repo+"lake-manifest.json",
 "SHA256SUMS":mit+"SHA256SUMS","audit.log":mit+"audit.log","nanoda.log":mit+"nanoda.log",
 "con-leche-compare.log":mit+"con-leche-compare.log","sandbox-timeline.txt":mit+"sandbox-timeline.txt",
 "zeta_definition.lean":"https://raw.githubusercontent.com/leanprover-community/mathlib4/v4.33.1/Mathlib/NumberTheory/LSeries/RiemannZeta.lean",
}
def get(item):
 name,url=item
 dest=root/"sources"/name
 proc=subprocess.run(["curl","-fsSL","--retry","2","--connect-timeout","10","--max-time","80",url,"-o",str(dest)],capture_output=True)
 if proc.returncode: return {"file":name,"url":url,"error":proc.returncode}
 data=dest.read_bytes()
 return {"file":name,"url":url,"sha256":hashlib.sha256(data).hexdigest(),"bytes":len(data),"retrieved":datetime.now(timezone.utc).isoformat()}
if __name__=="__main__":
 records=list(ThreadPoolExecutor(5).map(get,sources.items()))
 (root/"sources/index.json").write_text(json.dumps(records,indent=2))
 for r in records: print(r["file"],r.get("bytes",r.get("error")))

