-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate_event.py
More file actions
27 lines (20 loc) · 843 Bytes
/
create_event.py
File metadata and controls
27 lines (20 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import requests, json, sys, pathlib
from datetime import datetime, timedelta, timezone
SCRIPT_DIR = pathlib.Path(__file__).resolve().parent
LOG_FILE = SCRIPT_DIR / "screenshot_agent.log"
WEB_APP_URL = "" # <-- your URL
def log(msg: str):
with open(LOG_FILE, "a") as f:
f.write(f"{datetime.now().strftime('%-I:%M:%S %p')} - {msg}\n")
def _json_only(s: str) -> dict:
s = s.strip()
# If the model wrapped JSON in code fences or added prose, try to locate the first/last braces
start = s.find("{")
end = s.rfind("}")
if start != -1 and end != -1 and end > start:
s = s[start:end+1]
return json.loads(s)
parsed_json = _json_only(sys.argv[1])
payload = parsed_json
r = requests.post(WEB_APP_URL, headers={"Content-Type": "application/json"}, data=json.dumps(payload))
log(f"Event posted {r.text}")