#!/usr/bin/env python3 """Verify embedded legal HTML against the original PDFs (development: pypdf).""" from pathlib import Path import textwrap from pypdf import PdfReader ROOT = Path(__file__).resolve().parents[1] page = (ROOT / 'index.html').read_text() for name, filename, field in [ ('impressum', 'impressum_buchhandlung_am_markt_de.pdf', 'imprint_html_de'), ('datenschutz', 'datenschutzerklaerung_buchhandlung_am_markt_de.pdf', 'privacy_html_de'), ]: source = PdfReader(ROOT / 'design/legal' / filename).get_fields()[field]['/V'] source = source.replace('\r\n', '\n').replace('\r', '\n').strip() embedded = page.split(f'', 1)[1].split(f'', 1)[0] embedded = textwrap.dedent(embedded).strip() # The only markup addition is a focusable, labelled title for the dialog. embedded = embedded.replace(f'

', '

', 1) assert embedded == source, f'{name}: legal content differs from the supplied PDF' print(f'{name}: complete embedded HTML matches the supplied PDF ({len(source)} characters)')