Fix Cronicle event creation: fetch real category ID instead of hardcoded c_general

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-17 08:13:15 -04:00
parent 0e80e8b9df
commit c9c75b6be3
+21 -3
View File
@@ -30,7 +30,24 @@ async def _get_events() -> list[dict]:
return data.get("rows", [])
async def _create_event(title: str, script: str) -> str:
async def _get_first_category_id() -> str:
async with httpx.AsyncClient() as client:
resp = await client.get(
f"{_base_url()}/api/app/get_categories/v1",
params={"api_key": _api_key()},
timeout=10,
)
resp.raise_for_status()
data = resp.json()
if data.get("code") != 0:
raise RuntimeError(f"Cronicle get_categories error: {data}")
rows = data.get("rows", [])
if not rows:
raise RuntimeError("Cronicle has no categories configured")
return rows[0]["id"]
async def _create_event(title: str, script: str, category_id: str) -> str:
async with httpx.AsyncClient() as client:
resp = await client.post(
f"{_base_url()}/api/app/create_event/v1",
@@ -40,7 +57,7 @@ async def _create_event(title: str, script: str) -> str:
"enabled": 1,
"plugin": "shellplug",
"target": "allgrp",
"category": "c_general",
"category": category_id,
"timing": {},
"params": {"script": script},
"notes": "Auto-registered by raggr on startup",
@@ -80,7 +97,8 @@ async def ensure_cronicle_events() -> None:
+ " || "
+ trigger_cmd.format(url="http://raggr-blue:8080")
)
event_id = await _create_event(_SCHEDULED_MESSAGES_TITLE, script)
category_id = await _get_first_category_id()
event_id = await _create_event(_SCHEDULED_MESSAGES_TITLE, script, category_id)
logger.info(
"Cronicle: created '%s' (id=%s)", _SCHEDULED_MESSAGES_TITLE, event_id
)