"""Count the /api/ reads one idle /live-next tab makes (#343). Needs LD_LIBRARY_PATH as in the proof-shot script. 2026-09-15: 376/hour before 56405b0, 60/hour steady after."""
import time, collections
from playwright.sync_api import sync_playwright
hits=[]; 
with sync_playwright() as p:
    b=p.chromium.launch(args=["--use-gl=angle","--use-angle=swiftshader","--enable-unsafe-swiftshader"])
    pg=b.new_page(viewport={"width":1100,"height":700})
    t0=time.time()
    pg.on("request", lambda r: hits.append((round(time.time()-t0,1), r.url.split("hesper.untilnextsession.com")[-1].split("?")[0])) if "/api/" in r.url else None)
    pg.goto("https://hesper.untilnextsession.com/live-next")
    pg.wait_for_timeout(250000)
    b.close()
load=[h for h in hits if h[0]<10]; steady=[h for h in hits if h[0]>=10]
print("first 10 s:", collections.Counter(u for _,u in load))
print("times:", [t for t,u in steady]); print("10..250 s:", collections.Counter(u for _,u in steady))
print("steady per hour:", round(len(steady)/240*3600))
