#!/usr/bin/env python3 """Job #1502 source probe (read-only, public channels, no credentials). Question (return #708 / job #1501's route draft, "cheapest refuting check first"): does Motohashi 1976 (Proc. Japan Acad. 52, 273-275, Zbl 0355.10035, DOI 10.3792/pja/1195518296) transfer Bombieri-Vinogradov type distribution properties by a *divisibility* mechanism (sum over d | n) or by a *dispersion/bilinear* mechanism (sum_d g(d) sum_m ...)? Secondary, from job #1500's one-page-read obligation: the explicit Q(x), C, R(z) of Levin 1984 Thm 1 (Zbl 0547.10037) that decide the level of distribution. Every raw reply is written to work/job1502/sources/ and hashed; nothing is interpreted here, the report does the reading. Two channels, each calibrated in the same run. """ import hashlib import json import os 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; contact: local run)", "Accept": "application/json, text/html, application/xml;q=0.8"} def fetch(url, tries=3, timeout=45, 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: # network hiccup: bounded retry last = repr(e) time.sleep(2 + 2 * i) return None, (last or "unknown error").encode(), url def save(name, body): path = os.path.join(OUT, name) with open(path, "wb") as f: f.write(body) return {"file": name, "bytes": len(body), "sha256": hashlib.sha256(body).hexdigest()} def textish(body): """Crude tag strip good enough to decide whether a page carries the paper text.""" import re s = body.decode("utf-8", "replace") s = re.sub(r"(?is)<(script|style)[^>]*>.*?", " ", s) s = re.sub(r"(?s)<[^>]+>", " ", s) s = re.sub(r" ?", " ", s) s = re.sub(r"\s+", " ", s) return s.strip() def zbmath(query, label, n=10): url = ("https://api.zbmath.org/v1/document/_search?search_string=" + urllib.parse.quote(query) + "&results_per_page=%d&page=0" % n) status, body, final = fetch(url) rec = {"label": label, "channel": "zbmath_api", "query": query, "url": url, "status": status, "served_url": final, **save("%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") hits.append({ "title": t.get("title") if isinstance(t, dict) else t, "year": r.get("year"), "source": r.get("source"), "zbmath_url": r.get("zbmath_url"), "identifier": r.get("identifier"), "review_text": (r.get("editorial_contributions") or [{}])[0].get("text") if r.get("editorial_contributions") else None, }) except Exception as e: hits = [{"parse_error": repr(e)}] rec["hits"] = len(hits) rec["results"] = hits return rec def main(): rec = {"file": "job1502-sources.json", "channels": [], "paper_fetch": []} # --- zbMATH channel, calibrated in-run ------------------------------------- rec["channels"].append(zbmath("Jacobsthal function", "cal-zbmath-control", n=3)) rec["channels"].append(zbmath("Motohashi 1976 distribution of arithmetic functions", "zbmath-motohashi", n=10)) rec["channels"].append(zbmath("Moebius function arithmetic progressions Bombieri", "zbmath-levin", n=10)) time.sleep(2) # --- the 1976 text itself: DOI -> publisher (Proc. Japan Acad. is open) ---- doi = "https://doi.org/10.3792/pja/1195518296" status, body, final = fetch(doi, accept="text/html,application/xhtml+xml") rec["paper_fetch"].append({"label": "doi-landing", "url": doi, "status": status, "served_url": final, **save("doi-landing.html", body), "text_head": textish(body)[:600]}) # projecteuclid listing for the volume, and a direct pja path, tried blindly for label, url in [ ("pja-article", "https://www.jstage.jst.go.jp/article/pjab/52/6/52_6_273/_article"), ("projeuclid-search", "https://projecteuclid.org/search?q=" + urllib.parse.quote("Motohashi distribution of arithmetic functions")), ]: status, body, final = fetch(url, accept="text/html,application/xhtml+xml") rec["paper_fetch"].append({"label": label, "url": url, "status": status, "served_url": final, **save("%s.html" % label, body), "text_head": textish(body)[:400]}) time.sleep(1) path = os.path.join(HERE, "job1502-sources.json") with open(path, "w") as f: json.dump(rec, f, indent=1, sort_keys=True) print("wrote", path) for c in rec["channels"]: print("%-24s %-8s status=%s hits=%s sha=%s" % (c["label"], c["channel"], c["status"], c.get("hits"), c["sha256"][:12])) for p in rec["paper_fetch"]: print("%-24s %-8s status=%s bytes=%s sha=%s" % (p["label"], "fetch", p["status"], p["bytes"], p["sha256"][:12])) return 0 if __name__ == "__main__": sys.exit(main())