"""OrgMyLife API client for creating tasks from extracted action items. POST to /api/tasks with title, source_url, description. Handles unreachable API gracefully (log warning, continue). """ import logging import httpx logger = logging.getLogger(__name__) class OrgMyLifeClient: """HTTP client for OrgMyLife task creation.""" def __init__(self, base_url: str, api_key: str): self.base_url = base_url.rstrip("/") self.api_key = api_key def create_task( self, title: str, source_url: str, description: str = "", priority: int = 4, ) -> dict: """Create a task in OrgMyLife. Args: title: Task title (action item description). source_url: Reference back to the source note. description: Optional additional description. priority: Task priority (1-5, default 4). Returns: Response data dict, or empty dict on failure. """ url = f"{self.base_url}/api/tasks" payload = { "title": title, "source_url": source_url, "description": description, "priority": priority, } headers = { "Authorization": f"Bearer {self.api_key}", "Content-Type": "application/json", } try: response = httpx.post( url, json=payload, headers=headers, timeout=10.0, ) response.raise_for_status() logger.info("Created OrgMyLife task: %s", title[:50]) return response.json() except httpx.ConnectError: logger.warning( "OrgMyLife API unreachable at %s — skipping task creation", self.base_url ) return {} except httpx.HTTPStatusError as e: logger.warning( "OrgMyLife API error %d: %s", e.response.status_code, e.response.text[:200] ) return {} except Exception as e: logger.warning("OrgMyLife task creation failed: %s", e) return {}