#!/usr/bin/env python3 """Print the prose of posts of SpritesMind thread 386, with every code block left out. Used for the provenance audit (docs/provenance-audit.md). restart.md rule 10: code fragments in a post are not read, whoever wrote them. This script therefore - replaces every code box by the line ``[code block: not read]``; - replaces every quoted block by ``[quote: not read]`` when asked to (``--no-quotes``, and always for the posts docs/phase0.md lists as carrying emulator source lines inside quotations); - drops any remaining line that looks like program text (ends in ``;`` or ``{``, starts with ``//`` or ``/*``, or holds an assignment or a C-style call with a semicolon), printing ``[line that looks like code: not read]`` in its place; - refuses the posts docs/phase0.md lists as relaying an excluded model's code in prose. python scripts/post_prose.py p7967 p8025 print posts python scripts/post_prose.py --sizes p7967 ... only author, date and length The thread's pages are fetched by scripts/fetch_references.py into reference/. """ from __future__ import annotations import glob import html import re import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] PAGES = ROOT / "reference" / "spritesmind" #: Posts in which emulator source lines sit inside quotations or the author's own #: text (docs/phase0.md, "Slips", item 1). Their quotations are never printed. QUOTED_EMULATOR_SOURCE = { "5630", "5639", "5730", "6219", "6225", "6237", "8905", "6519", "10460", } # fmt: skip #: Posts that relay an excluded model's code in prose (docs/phase0.md, "Slips", #: item 2; handoff-brief.md decision P4). Never printed. RELAYED_MODEL = { "29476", "29508", "30935", "30938", "31050", "32605", "16391", "34276", "34277", "34281", "34289", } # fmt: skip #: Authors of excluded models (handoff-brief.md decision P4): their forum prose is #: not a source for this core. EXCLUDED_AUTHORS = {"nukeykt", "jotego"} CODE_LINE = re.compile( r"""(;\s*$)|(\{\s*$)|(^\s*\})|(^\s*//)|(^\s*/\*)|(\*/\s*$)|(^\s*\#\s*(define|include|if)) |(\w\s*(\+|-|\||&|<<|>>)?=\s*[\w(~\-!].*;)|(\b(if|for|while)\s*\(.*\)\s*$)""", re.VERBOSE, ) def posts() -> dict[str, tuple[str, str, str]]: found = {} for page in sorted(glob.glob(str(PAGES / "t386-*.html"))): text = Path(page).read_text(encoding="utf-8", errors="replace") parts = re.split(r'