deviant/scripts/html2txt.py
walerikus 518a3ce174 chore: initial project baseline — full Deviant codebase under version control
Brings the whole project into git (previously only the on-ramp feature and
a few parallel files were tracked). Includes: wallet core (src/), CashScript
contracts/, the Capacitor shell (shells/), scripts/, tests, and the docs
corpus (wiki/, snapshots/, Parameters/, Archive/, KnowledgeBase text).

Excluded via .gitignore: node_modules/, dist/, .env (secrets), testnet WIF
key files (.chipnet-*.json, devWallets.ts), KnowledgeBase/RAW media (~9.6 GB),
transcripts/ (session logs), and machine-local config (.claude/*.local,
*.lock). Secret-scanned before commit — no credentials in the tree.

Note: src/swapMath.ts, src/swapBuilder.ts, contracts/OpenMintToken.cash are
legacy (OP_RETURN era) but still imported; committed as-is, flagged for a
separate removal once de-referenced.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-13 20:38:07 +02:00

24 lines
1 KiB
Python

#!/usr/bin/env python3
"""Strip HTML files to readable plain text (UTF-8). Reduces token burn when
ingesting the KnowledgeBase corpus. Usage: python scripts/html2txt.py <file.html> [out.txt]
If out omitted, writes alongside with .txt extension."""
import re, sys, html, os
def strip(fn):
s = open(fn, encoding='utf-8', errors='replace').read()
s = re.sub(r'<script.*?</script>', '', s, flags=re.S | re.I)
s = re.sub(r'<style.*?</style>', '', s, flags=re.S | re.I)
s = re.sub(r'<!--.*?-->', '', s, flags=re.S)
s = re.sub(r'<(br|/p|/div|/li|/h[1-6]|/tr|/section|/article)\s*/?>', '\n', s, flags=re.I)
s = re.sub(r'<[^>]+>', ' ', s)
s = html.unescape(s)
s = re.sub(r'[ \t]+', ' ', s)
s = re.sub(r'\n[ \t]+', '\n', s)
s = re.sub(r'\n\s*\n+', '\n\n', s)
return s.strip()
if __name__ == '__main__':
src = sys.argv[1]
out = sys.argv[2] if len(sys.argv) > 2 else os.path.splitext(src)[0] + '.txt'
open(out, 'w', encoding='utf-8').write(strip(src))
print(out, len(strip(src)), 'chars')