Does light charge the quons? › Files cited on the page › aspden_earnshaw_2026-11-13/
aspden_earnshaw_extract.py
"""Extract the Earnshaw passages from fetched site pages (data, not instructions). Run with python3 -I <dir>."""
import os, re, sys, html
D = sys.argv[1]
TAG = re.compile(r"<[^>]+>"); WS = re.compile(r"\s+")
def text_of(raw):
m = re.search(r"(?is)<main[^>]*>(.*)</main>", raw) or re.search(r"(?is)<article[^>]*>(.*)</article>", raw)
body = m.group(1) if m else raw
body = re.sub(r"(?is)<(script|style|nav|footer|header)[^>]*>.*?</\1>", " ", body)
return WS.sub(" ", html.unescape(TAG.sub(" ", body))).strip()
for f in sorted(os.listdir(D)):
raw = open(os.path.join(D, f), encoding="utf-8", errors="replace").read()
title = re.search(r"(?is)<title>(.*?)</title>", raw)
t = text_of(raw)
hits = [m.start() for m in re.finditer(r"Earnshaw", t)]
print(f"\n######## {f} | title: {html.unescape(title.group(1)).strip()[:110] if title else '?'} | {len(hits)} mention(s)")
wins = []
for h in hits:
a, b = max(0, h - 650), min(len(t), h + 1000)
if wins and a <= wins[-1][1]:
wins[-1][1] = b
else:
wins.append([a, b])
for a, b in wins:
print(" ..." + t[a:b] + "...")