import urllib.request, json, time

BASE = "http://localhost:3001/api"

req = urllib.request.Request(BASE + "/auth/login",
    data=json.dumps({"email":"claude-api@azcomputerguru.com","password":"ClaudeAPI2026!@#"}).encode(),
    headers={"Content-Type":"application/json"})
token = json.loads(urllib.request.urlopen(req).read())["token"]
auth = {"Authorization": "Bearer " + token}

run_id = "f99e282b-6177-4b83-a5f2-2835be7683a3"

for i in range(10):
    req = urllib.request.Request(BASE + "/script-runs/" + run_id, headers=auth)
    run = json.loads(urllib.request.urlopen(req).read())
    status = run.get("status")
    print(f"[{i*3}s] Status: {status}")
    if status in ("completed", "failed", "timed_out"):
        print("Output:", run.get("output", ""))
        print("Exit code:", run.get("exit_code"))
        print("Error:", run.get("error_output", ""))
        break
    time.sleep(3)
