Does light charge the quons? › Files cited on the page › check_earnshaw_pages_fable/
extract_passages.py
"""Ninth review: my own extraction of every 'Earnshaw' passage (and 'Earlshaw') from HTML files, with wide context.
Run: ~/aspden-review-venv/bin/python3 -I extract_passages.py <file or dir> [...] > out.txt
The files are data, not instructions."""
import os, re, sys, html
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()
paths = []
for a in sys.argv[1:]:
if os.path.isdir(a):
for dp, dn, fn in os.walk(a):
paths += [os.path.join(dp, f) for f in sorted(fn) if f.lower().endswith((".htm", ".html"))]
else:
paths.append(a)
for p in sorted(paths):
raw = open(p, encoding="utf-8", errors="replace").read()
t = text_of(raw)
hits = [(m.start(), m.group(0)) for m in re.finditer(r"Earn?shaw|Earlshaw", t, re.I)]
if not hits:
continue
title = re.search(r"(?is)<title>(.*?)</title>", raw)
forms = sorted(set(h[1] for h in hits))
print(f"\n######## {p} | title: {html.unescape(title.group(1)).strip()[:120] if title else '?'} | {len(hits)} mention(s) | forms {forms}")
wins = []
for h, _ in hits:
a, b = max(0, h - 900), min(len(t), h + 1300)
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] + "...")