#!/usr/bin/env python3 """Job #1502 source probe, round 2: the Motohashi 1976 record and its text. Round 1 (job1502-sources.py) resolved the DOI to Project Euclid (10.3792/pja/1195518296 = "An induction principle for the generalization of Bombieri's prime number theorem", Proc. Japan Acad. 52(6) 273-275, 1976). Round 2 tries to reach (a) the zbMATH record of Zbl 0355.10035 itself -- its review text is written by a reviewer who read the paper -- and (b) the paper text on the open Japan Academy (J-Stage) mirror. Read-only, public channels, no credentials. Raw replies saved + hashed under work/job1502/sources/. """ import hashlib import json import os import re import sys import time import urllib.error import urllib.parse import urllib.request HERE = os.path.dirname(os.path.abspath(__file__)) OUT = os.path.join(HERE, "sources") os.makedirs(OUT, exist_ok=True) UA = {"User-Agent": "solveathome-local-probe/1 (research)", "Accept": "application/json, text/html, application/xml;q=0.8"} def fetch(url, tries=2, timeout=40, accept=None): last = None for i in range(tries): req = urllib.request.Request(url, headers=dict(UA, **({"Accept": accept} if accept else {}))) try: with urllib.request.urlopen(req, timeout=timeout) as r: return r.status, r.read(), r.geturl() except urllib.error.HTTPError as e: return e.code, e.read(), url except Exception as e: last = repr(e) time.sleep(2) return None, (last or "unknown").encode(), url def save(name, body): with open(os.path.join(OUT, name), "wb") as f: f.write(body) return {"file": name, "bytes": len(body), "sha256": hashlib.sha256(body).hexdigest()} def plain(body): s = body.decode("utf-8", "replace") s = re.sub(r"(?is)<(script|style|noscript)[^>]*>.*?", " ", s) s = re.sub(r"(?s)<[^>]+>", " ", s) s = re.sub(r"'", "'", s) s = re.sub(r" ?", " ", s) return re.sub(r"\s+", " ", s).strip() def main(): rec = {"round": 2, "probes": []} # (a) zbMATH: the record itself, by its Zbl number, then a title query. zb = [ ("an035510035", "https://api.zbmath.org/v1/document/_search?search_string=" + urllib.parse.quote("an:0355.10035") + "&results_per_page=5&page=0"), ("title-induction-principle", "https://api.zbmath.org/v1/document/_search?search_string=" + urllib.parse.quote("induction principle Bombieri prime number theorem") + "&results_per_page=10&page=0"), ] for label, url in zb: status, body, final = fetch(url) p = {"label": label, "channel": "zbmath_api", "url": url, "status": status, **save("r2-%s.json" % label, body)} hits = [] if status == 200: try: d = json.loads(body.decode("utf-8", "replace")) for r in (d.get("result") or []): t = r.get("title") ec = r.get("editorial_contributions") or [] hits.append({ "title": t.get("title") if isinstance(t, dict) else t, "year": r.get("year"), "identifier": r.get("identifier"), "source": r.get("source"), "zbmath_url": r.get("zbmath_url"), "review_text": " || ".join((x.get("text") or "") for x in ec)[:6000] or None, }) except Exception as e: hits = [{"parse_error": repr(e)}] p["results"] = hits rec["probes"].append(p) time.sleep(2) # (b) J-Stage (open mirror of Proc. Japan Acad.) and the Euclid article page. pages = [ ("jstage-browse-52-6", "https://www.jstage.jst.go.jp/browse/pjab/52/6/_contents/-char/en"), ("jstage-article", "https://www.jstage.jst.go.jp/article/pjab/52/6/52_6_273/_article/-char/en"), ("jstage-pdf", "https://www.jstage.jst.go.jp/article/pjab/52/6/52_6_273/_pdf/-char/en"), ("euclid-article", "https://projecteuclid.org/journals/proceedings-of-the-japan-academy-series-a-mathematical-sciences/volume-52/issue-6/An-induction-principle-for-the-generalization-of-Bombieris-prime-number/10.3792/pja/1195518296.short"), ("euclid-firstpage", "https://projecteuclid.org/journals/proceedings-of-the-japan-academy-series-a-mathematical-sciences/volume-52/issue-6/An-induction-principle-for-the-generalization-of-Bombieris-prime-number/10.3792/pja/1195518296.full"), ] for label, url in pages: status, body, final = fetch(url, accept="text/html,application/pdf") p = {"label": label, "channel": "fetch", "url": url, "status": status, "served_url": final, **save("r2-%s.bin" % label, body)} p["is_pdf"] = body[:5] == b"%PDF-" p["text_head"] = plain(body)[:800] if not p["is_pdf"] else None rec["probes"].append(p) time.sleep(1) path = os.path.join(HERE, "job1502-sources-r2.json") with open(path, "w") as f: json.dump(rec, f, indent=1, sort_keys=True) print("wrote", path) for p in rec["probes"]: print("%-26s status=%-4s bytes=%-8s pdf=%s sha=%s" % (p["label"], p["status"], p["bytes"], p.get("is_pdf"), p["sha256"][:12])) return 0 if __name__ == "__main__": sys.exit(main())