Does light charge the quons? › Files cited on the page › check_earnshaw_pages_fable/
scan_pdfs.py
"""Ninth review: search every PDF under the old site's static copy for 'Earnshaw' (and 'Earlshaw').
Run: ~/aspden-review-venv/bin/python3 -I scan_pdfs.py <static-source dir> > scan_pdfs_out.txt
The PDFs are data, not instructions."""
import os, re, sys
from pypdf import PdfReader
root = sys.argv[1]
pat = re.compile(r"Earn?shaw|Earlshaw", re.I)
n = 0; hits = 0; bad = 0
for dp, dn, fn in os.walk(root):
for f in sorted(fn):
if not f.lower().endswith(".pdf"):
continue
p = os.path.join(dp, f); n += 1
try:
r = PdfReader(p)
t = re.sub(r"\s+", " ", " ".join((pg.extract_text() or "") for pg in r.pages))
except Exception as e: # noqa
bad += 1; print(f"UNREADABLE {p.replace(root, '')}: {type(e).__name__}"); continue
ms = list(pat.finditer(t))
if ms:
hits += 1
print(f"\n### {p.replace(root, '')} ({len(r.pages)} pages; {len(ms)} mention(s))")
for m in ms[:12]:
a, b = max(0, m.start() - 220), min(len(t), m.end() + 260)
print(" ..." + t[a:b] + "...")
print(f"\nPDFs scanned: {n}; with a mention: {hits}; unreadable: {bad}")