run.py raw
1 #!/usr/bin/env python3
2 """Render a verification verdict in the page, from a dossier decided outside it.
3
4 usage: DOSSIER=/tmp/dossier.json run.py
5 """
6
7 import asyncio
8 import os
9 import shutil
10
11 from playwright.async_api import async_playwright
12
13 HERE = os.path.dirname(os.path.abspath(__file__))
14 DOSSIER = os.environ.get("DOSSIER", "/tmp/dossier.json")
15 PROFILE = os.path.join(HERE, "chromium-profile")
16 PAGE = os.environ.get("PAGE", "http://127.0.0.1:8080/?chains=blake&network=xbt")
17
18
19 async def main():
20 text = open(DOSSIER).read()
21 print("dossier bytes:", len(text))
22
23 async with async_playwright() as p:
24 context = await p.chromium.launch_persistent_context(
25 PROFILE, viewport={"width": 1280, "height": 1600})
26 page = context.pages[0] if context.pages else await context.new_page()
27 page.on("console", lambda m: print("console:", m.text))
28
29 cdp = await context.new_cdp_session(page)
30 await cdp.send("Network.clearBrowserCache")
31
32 await page.goto(PAGE, wait_until="load", timeout=60000)
33
34 card = page.locator("#cards .card").first
35 await card.locator("input").nth(0).fill("wss://swaprelay.smesh.lol")
36 await page.get_by_role("button", name="Connect").click()
37 await page.wait_for_function(
38 "document.getElementById('connect-status').textContent.includes('connected')",
39 timeout=120000)
40 print("connected")
41
42 await page.locator("#dossier").fill(text)
43 await page.get_by_role("button", name="Verify").click()
44 await page.wait_for_function(
45 "document.getElementById('verify-report').textContent.includes('verified by')",
46 timeout=60000)
47
48 report = await page.locator("#verify-report").inner_text()
49 print(report.splitlines()[:6])
50
51 await page.screenshot(path=os.path.join(HERE, "01-verdict.png"), full_page=True)
52 await context.close()
53
54
55 asyncio.run(main())
56