"""Fetch the inputs of our analysis and check them against the copies we used. Fact-Checked Science ("Our analysis"), 20 November 2026, for the check of Marschollek, M., "Age and Sex Differences in Causal Impact of Geomagnetic Ap on Cardiac Arrest Incidence during and after Solar Storms", AGU26 abstract GH11D-VR9816 (not peer reviewed). What it fetches (identifying itself as "factchecked-research/1.0"), into : gfz-kp/Kp_ap_Ap_SN_F107_since_1932.txt GFZ Helmholtz Centre for Geosciences, https://kp.gfz.de/app/files/Kp_ap_Ap_SN_F107_since_1932.txt (Kp, ap and Ap: CC BY 4.0; Matzka et al. 2021, doi:10.5880/Kp.0001; about 5.5 MB). GFZ appends a day every day, so the whole file never matches our copy again: the script checks the SHA-256 of the lines for 2014-01-01 to 2019-12-31 (all definitive) instead. cdc-nchs/rows_3yf8-kanr.csv CDC/NCHS, "Weekly Counts of Deaths by State and Select Causes, 2014-2019", data.cdc.gov dataset 3yf8-kanr, CSV export (public domain; about 2.4 MB). cdc-nchs/resource_3yf8-kanr_united_states.json The same dataset's United States rows through the SODA API (read by weekly_deaths_check.py). For the two CDC files the script checks the whole file and, if that differs (an export can change its formatting), the SHA-256 of the United States rows' year, week, week-ending date, heart-disease and all-cause counts, written one row per line. Needs Python 3.9+ (standard library only). Run: python3 fetch_inputs.py Files already present that pass the check are kept. On a mismatch the script stops and says which file differs; the download is kept as .mismatch for inspection. """ import csv import hashlib import io import json import os import sys import urllib.error import urllib.request UA = "factchecked-research/1.0" GFZ_URL = "https://kp.gfz.de/app/files/Kp_ap_Ap_SN_F107_since_1932.txt" CDC_CSV_URL = "https://data.cdc.gov/api/views/3yf8-kanr/rows.csv?accessType=DOWNLOAD" CDC_JSON_URL = ("https://data.cdc.gov/resource/3yf8-kanr.json?jurisdiction_of_occurrence=United%20States" "&%24limit=5000") # SHA-256 of the copies we used (fetched 2026-11-20, 19:14-19:19 UTC) and of the rows we read from them GFZ_FILE = "5f479a3d98019dbe2324e9dd744932bfb894380ca1b3e9911307b497f890d884" GFZ_ROWS_2014_2019 = "be59a1bef4519c16c495193d0cbc7a523f224c02c6cff5d33f0fa40edec24e9d" CDC_CSV_FILE = "4917c1141fc48c64160d92ce912c9971e22d57571840b266412f715b1252edca" CDC_JSON_FILE = "2ff3e9b76d986dff6b0beb3458aa872981faae2fe59e7bb6442e51858d4a406b" CDC_US_ROWS = "b1b87e9796ead470388c1a55aeeadf255ef048451b931878d18d0a4c7587dd58" HEART = "Diseases of heart (I00-I09,I11,I13,I20-I51)" def sha256_bytes(b): return hashlib.sha256(b).hexdigest() def gfz_rows(b): keep = [] for line in b.decode("utf-8").splitlines(): if line.startswith("#") or not line.strip(): continue y = int(line[:4]) if 2014 <= y <= 2019: keep.append(line.rstrip()) return sha256_bytes(("\n".join(keep) + "\n").encode()) def us_rows_csv(b): rows = [] for r in csv.DictReader(io.StringIO(b.decode("utf-8"))): if r["Jurisdiction of Occurrence"] == "United States": end = r["Week Ending Date"] if "/" in end: # MM/DD/YYYY mm, dd, yy = end.split("/") end = f"{yy}-{mm}-{dd}" rows.append((int(r["MMWR Year"]), int(r["MMWR Week"]), end[:10], int(float(r[HEART].replace(",", ""))), int(float(r["All Cause"].replace(",", ""))))) return canon(rows) def us_rows_json(b): rows = [(int(r["mmwryear"]), int(r["mmwrweek"]), r["weekendingdate"][:10], int(float(r["diseases_of_heart_i00_i09"])), int(float(r["allcause"]))) for r in json.loads(b.decode("utf-8")) if r["jurisdiction_of_occurrence"] == "United States"] return canon(rows) def canon(rows): rows.sort() return sha256_bytes("".join(f"{a},{b},{c},{d},{e}\n" for a, b, c, d, e in rows).encode()) def download(url): req = urllib.request.Request(url, headers={"User-Agent": UA}) try: with urllib.request.urlopen(req, timeout=600) as r: return r.read() except urllib.error.HTTPError as e: sys.exit(f"STOP: {url} answered HTTP {e.code}. Nothing was retried; fetch it by hand if you can.") except urllib.error.URLError as e: sys.exit(f"STOP: could not reach {url}: {e.reason}") def get(folder, sub, name, url, file_hash, rows_fn, rows_hash): os.makedirs(os.path.join(folder, sub), exist_ok=True) path = os.path.join(folder, sub, name) if os.path.exists(path): b = open(path, "rb").read() source = "have " else: b = download(url) source = "fetched" if sha256_bytes(b) == file_hash: how = "whole file matches our copy" elif rows_fn(b) == rows_hash: how = "the rows we used match our copy (the rest of the file differs)" else: with open(path + ".mismatch", "wb") as f: f.write(b) sys.exit(f"STOP: {name} differs from the copy we used, in the rows we read.\n URL: {url}\n" f" kept as {path}.mismatch. Results computed from it may differ from ours.") if source == "fetched": with open(path, "wb") as f: f.write(b) print(source, path, "-", how) def main(): if len(sys.argv) != 2: sys.exit("usage: python3 fetch_inputs.py ") folder = sys.argv[1] get(folder, "gfz-kp", "Kp_ap_Ap_SN_F107_since_1932.txt", GFZ_URL, GFZ_FILE, gfz_rows, GFZ_ROWS_2014_2019) get(folder, "cdc-nchs", "rows_3yf8-kanr.csv", CDC_CSV_URL, CDC_CSV_FILE, us_rows_csv, CDC_US_ROWS) get(folder, "cdc-nchs", "resource_3yf8-kanr_united_states.json", CDC_JSON_URL, CDC_JSON_FILE, us_rows_json, CDC_US_ROWS) print("All inputs present and matching our copies.") if __name__ == "__main__": main()