Explorer
/tmp/test_cron.py
← Zurück ↓ Download
import urllib.request, json, urllib.error, http.cookiejar, re

cookie_jar = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie_jar))

# Try fetching the root page first
with opener.open("http://127.0.0.1:5100/", timeout=10) as r:
    html = r.read().decode()
    match = re.search(r"window\.__CLAUDE_SESSION_TOKEN__\s*=\s*[\"'](.+?)[\"']", html)
    if match:
        token = match.group(1)
        print("Found token:", token[:20] + "...")
    else:
        print("No token found in HTML")

# Now try creating a cron job
payload = json.dumps({"prompt": "Test prompt", "schedule": "every 30m", "name": "Test Job", "deliver": ["local"]}).encode()
req = urllib.request.Request("http://127.0.0.1:5100/api/claude-jobs", data=payload, headers={"Content-Type": "application/json"}, method="POST")
try:
    with opener.open(req, timeout=30) as r:
        print("create job:", r.status)
        print(r.read().decode())
except urllib.error.HTTPError as e:
    print("create job error:", e.code, e.read().decode())
except Exception as e:
    print("create job error:", e)