#!/usr/bin/env python3 """Re-run our check of the reference list of Blanc et al. (2026) (rules: RULES_refcheck.txt). Usage: python3 -I refcheck_rerun.py Standard library only (Python 3.8 or later). Fetches under a plain client name, at most one request a second; about 70 requests, so it takes a few minutes. What it does: 1. Fetches the paper's Crossref record and takes the reference list the publisher deposited (66 entries). Crossref's record changes over time in other fields, so the script checks the SHA-256 of the reference list alone (as compact JSON with sorted keys) against ours. 2. Looks up each DOI at Crossref, then DataCite, then the DOI handle service, and takes the registered title. 3. A reference passes if at least 80% of the registered title's words (lower case, letters and digits, words of three or more characters) occur in the printed reference; otherwise it is flagged for reading by hand. Our reading of the six flags is in refcheck-manual.txt. Writes /out/refcheck-results.csv (without the printed references, which are the paper's text) and compares it with the refcheck-results.csv we host. """ import csv import hashlib import io import json import re import sys import time import urllib.error import urllib.parse import urllib.request from pathlib import Path HERE = Path(__file__).resolve().parent DOI = "10.1007/s10712-026-09968-1" REFS_SHA256 = "43e4490d3ce24e4a247ad44e744dc6144b0c16b1b89bd581c1e81ec59eaf1cff" UA = {"User-Agent": "factchecked-research/1.0"} FIELDS = ["key", "doi", "where", "status", "registered_title", "share_of_title_words_found", "result"] def get_json(url): req = urllib.request.Request(url, headers=UA) try: with urllib.request.urlopen(req, timeout=60) as r: return r.status, json.loads(r.read()) except urllib.error.HTTPError as e: return e.code, None except Exception: return -1, None def words(s): return [w for w in re.findall(r"[a-z0-9]+", s.lower()) if len(w) >= 3] def main(argv): if not argv: sys.exit(__doc__) out = Path(argv[0]) / "out" out.mkdir(parents=True, exist_ok=True) st, rec = get_json("https://api.crossref.org/works/" + DOI) if st != 200: sys.exit(f"Crossref answered {st}. Stopping.") refs = rec["message"]["reference"] canon = json.dumps(refs, sort_keys=True, ensure_ascii=False, separators=(",", ":")).encode("utf-8") digest = hashlib.sha256(canon).hexdigest() print(f"{len(refs)} references; SHA-256 of the list {digest}:", "same as ours" if digest == REFS_SHA256 else f"NOT ours ({REFS_SHA256})") rows = [] for r in refs: doi = r.get("DOI") printed = r.get("unstructured") or "" row = {"key": r.get("key"), "doi": doi or "", "where": "", "status": "", "registered_title": "", "share_of_title_words_found": "", "result": ""} if not doi: row["result"] = "NO DOI" rows.append(row) continue q = urllib.parse.quote(doi) st, js = get_json("https://api.crossref.org/works/" + q) time.sleep(1) title = "" if st == 200: row["where"] = "Crossref" title = (js["message"].get("title") or [""])[0] else: st2, js2 = get_json("https://api.datacite.org/dois/" + q) time.sleep(1) if st2 == 200: row["where"] = "DataCite" title = (js2["data"]["attributes"].get("titles") or [{}])[0].get("title", "") else: st3, js3 = get_json("https://doi.org/api/handles/" + q) time.sleep(1) row["where"] = ("handle only" if st3 == 200 and js3 and js3.get("responseCode") == 1 else "not registered") st = st3 row["status"] = st row["registered_title"] = re.sub(r"\s+", " ", title).strip() tw, pw = words(title), set(words(printed)) if tw: share = sum(w in pw for w in tw) / len(tw) row["share_of_title_words_found"] = f"{share:.2f}" row["result"] = "PASS" if share >= 0.8 else "FLAG" else: row["result"] = "FLAG" rows.append(row) print(row["key"], doi, row["where"], row["result"], row["share_of_title_words_found"]) buf = io.StringIO() w = csv.DictWriter(buf, fieldnames=FIELDS, lineterminator="\n") w.writeheader() w.writerows(rows) data = buf.getvalue().encode("utf-8") (out / "refcheck-results.csv").write_bytes(data) counts = {k: sum(x["result"] == k for x in rows) for k in ("PASS", "FLAG", "NO DOI")} print("PASS {PASS}, FLAG {FLAG}, NO DOI {NO DOI}".format(**counts)) hosted = HERE / "refcheck-results.csv" if hosted.exists(): print("Same as our hosted refcheck-results.csv:", "yes" if hosted.read_bytes() == data else "NO") print("SHA-256 of out/refcheck-results.csv:", hashlib.sha256(data).hexdigest()) if __name__ == "__main__": main(sys.argv[1:])