2026-04-15 17:06:04 +05:30
|
|
|
#!/usr/bin/env -S uv run --script
|
|
|
|
|
|
|
|
|
|
# /// script
|
|
|
|
|
# dependencies = [
|
|
|
|
|
# "playwright",
|
|
|
|
|
# ]
|
|
|
|
|
# ///
|
2022-09-18 16:12:57 +01:00
|
|
|
|
|
|
|
|
import subprocess
|
2026-04-15 17:06:04 +05:30
|
|
|
import sys
|
2026-04-10 22:39:28 +05:30
|
|
|
import tempfile
|
2022-09-18 16:12:57 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
2026-04-15 17:06:04 +05:30
|
|
|
from playwright.sync_api import sync_playwright # type: ignore[import-not-found]
|
2026-04-10 22:39:28 +05:30
|
|
|
|
2026-04-15 17:06:04 +05:30
|
|
|
CSS = """
|
|
|
|
|
<link href="https://fonts.googleapis.com/css2?family=Lato&display=swap" rel="stylesheet">
|
|
|
|
|
<style>
|
|
|
|
|
html, body {
|
|
|
|
|
font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
color: #404040;
|
|
|
|
|
background: white;
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
* {
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
"""
|
2022-09-18 16:12:57 +01:00
|
|
|
|
|
|
|
|
|
2024-10-22 10:16:59 -04:00
|
|
|
def main() -> None:
|
2026-04-15 17:06:04 +05:30
|
|
|
subprocess.run([sys.executable, "-m", "playwright", "install", "chromium"], check=True)
|
|
|
|
|
|
|
|
|
|
html_str = Path("docs/diagram.html").read_text()
|
|
|
|
|
html_str = f"<html><head>{CSS}</head><body>{html_str}</body></html>"
|
|
|
|
|
|
2026-04-10 22:39:28 +05:30
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir_str:
|
2026-04-15 17:06:04 +05:30
|
|
|
html_path = Path(tmp_dir_str) / "diagram_screenshot.html"
|
2026-04-10 22:39:28 +05:30
|
|
|
html_path.write_text(html_str)
|
2022-09-18 16:12:57 +01:00
|
|
|
|
2026-04-10 22:39:28 +05:30
|
|
|
dest_path = Path("docs/data/how-it-works.png")
|
2022-09-18 16:12:57 +01:00
|
|
|
|
2026-04-10 22:39:28 +05:30
|
|
|
with sync_playwright() as p:
|
|
|
|
|
browser = p.chromium.launch()
|
|
|
|
|
page = browser.new_page(device_scale_factor=2, viewport={"width": 830, "height": 600})
|
|
|
|
|
page.goto(html_path.as_uri())
|
|
|
|
|
page.wait_for_load_state("networkidle")
|
2022-09-18 16:12:57 +01:00
|
|
|
|
2026-04-10 22:39:28 +05:30
|
|
|
height = page.evaluate("document.body.scrollHeight")
|
|
|
|
|
page.set_viewport_size({"width": 830, "height": height})
|
|
|
|
|
|
|
|
|
|
page.screenshot(path=str(dest_path), full_page=True)
|
|
|
|
|
browser.close()
|
2022-09-18 16:12:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|