#!/usr/bin/env python3 """Renders our own made-up pages (HTML in git) into the screenshots the questions show (PNG, in the cache). python3 screen/render.py screen/webqa/pages [more dirs] [--out /screen/img] [--only w001,w002] Every `.html` becomes `/.png`. The page says how to shoot it in its head: 390 x 844 CSS px at 2x (an iPhone screenshot), the whole page down to 2400 px 1440 x 900 at 1x (a browser window), the whole page down to 2400 px any other size, at 1x only the first screen, not the whole page Pages use only macOS's own fonts (PingFang SC, Hiragino Sans GB, Songti SC, Menlo) and nothing from the network: every request leaving the page is blocked, so a page renders the same offline. The same page and the same machine give the same picture; other Macs may differ by a pixel here and there, which is why the PNGs themselves are what the release carries (vision-data-v1 / screen-data-v1), and this script is how they were made. Needs Playwright with its Chromium (`pip install playwright && playwright install chromium`). """ import argparse import os import re import sys CACHE = os.path.abspath(os.path.expanduser(os.environ.get("LUOKE_BENCH_CACHE") or "~/.cache/luoke-bench")) SIZES = {"phone": (390, 844, 2), "desktop": (1440, 900, 1)} MAX_H = 2400 def shot_of(html): m = re.search(r' {a.out}") if __name__ == "__main__": main()