# SPDX-License-Identifier: MIT """Gera os PNGs do infográfico a partir de index.html (fonte única dos números). python3 gerar-png.py Saída em png/: desktop e mobile, claro e escuro, e a capa 1200x630 (claro e escuro). """ from pathlib import Path from playwright.sync_api import sync_playwright AQUI = Path(__file__).resolve().parent PAGINA = (AQUI / "index.html").as_uri() SAIDA = AQUI / "png" SAIDA.mkdir(exist_ok=True) VARIANTES = { "desktop": dict(width=1200, height=900, scale=2), "mobile": dict(width=390, height=844, scale=3), } with sync_playwright() as p: nav = p.chromium.launch() for nome, v in VARIANTES.items(): for tema in ("light", "dark"): ctx = nav.new_context( viewport={"width": v["width"], "height": v["height"]}, device_scale_factor=v["scale"], color_scheme=tema, ) pg = ctx.new_page() pg.goto(PAGINA); pg.wait_for_timeout(300) pg.evaluate( "t => { document.documentElement.setAttribute('data-theme', t);" " document.querySelectorAll('.actions, .nav, .erro-box').forEach(e => e.style.display = 'none'); }", tema, ) destino = SAIDA / f"divida-2008-2025-{nome}-{tema}.png" pg.screenshot(path=str(destino), full_page=True) print(destino.name) ctx.close() # capa para galeria e og:image: 1200x630, sem retina (é o tamanho que as redes pedem) capa = (AQUI / "capa.html").as_uri() for tema in ("light", "dark"): ctx = nav.new_context(viewport={"width": 1200, "height": 630}, device_scale_factor=1) pg = ctx.new_page() pg.goto(capa) pg.evaluate("t => document.documentElement.setAttribute('data-theme', t)", tema) destino = SAIDA / f"divida-2008-2025-capa-{tema}.png" pg.screenshot(path=str(destino)) print(destino.name) ctx.close() nav.close()