Files
2608_BuB/scripts/verify-legal-content.py
André Fiedler 8d1e6742bf
showcase/deploy Live at https://showcase.andrefiedler.de/2608_BuB/
Add styled legal dialogs with unchanged supplied content
2026-09-10 11:35:39 +02:00

23 lines
1.1 KiB
Python

#!/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'<!-- legal:{name}:start -->', 1)[1].split(f'<!-- legal:{name}:end -->', 1)[0]
embedded = textwrap.dedent(embedded).strip()
# The only markup addition is a focusable, labelled title for the dialog.
embedded = embedded.replace(f'<h1 id="{name}-title" tabindex="-1">', '<h1>', 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)')