From d69107c624aff34a25c4a26ee2cfe6743483dacf Mon Sep 17 00:00:00 2001 From: Makesesama Date: Tue, 30 Jun 2026 20:27:29 +0200 Subject: [PATCH] fix: use khal 0.11.3 command --- sims/modules/calendar.py | 44 ++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/sims/modules/calendar.py b/sims/modules/calendar.py index bdaa84d..01d02e6 100644 --- a/sims/modules/calendar.py +++ b/sims/modules/calendar.py @@ -1,4 +1,3 @@ -import json import os import subprocess import shutil @@ -131,18 +130,19 @@ class CalendarService: return try: + # khal 0.11.3 does not support the newer `--json` output flags. + # Use the documented `list --format ... --day-format ... START DELTA` + # form instead and parse one event per line. `{bell}` is an uncommon + # control-code delimiter supported by khal's formatter. cmd = [ khal_path, "list", - "--json", - "title", - "--json", - "start", - "--json", - "end", - "--json", - "location", + "--format", + "{start-date}{bell}{start-time}{bell}{end-date}{bell}{end-time}{bell}{title}{bell}{location}", + "--day-format", + "", "today", + "eod", ] logger.info(f"[Calendar] Running command: {' '.join(cmd)}") result = subprocess.run( @@ -155,16 +155,26 @@ class CalendarService: logger.info(f"[Calendar] Command stderr: {result.stderr[:200]}...") if result.stdout.strip(): - lines = result.stdout.strip().split("\n") all_events = [] - for line in lines: - if line.strip(): - try: - events = json.loads(line) - all_events.extend(events) - except json.JSONDecodeError: - continue + for line in result.stdout.splitlines(): + if not line.strip(): + continue + + parts = line.split("\a", 5) + if len(parts) != 6: + logger.warning(f"[Calendar] Could not parse khal output line: {line}") + continue + + start_date, start_time, end_date, end_time, title, location = parts + all_events.append( + { + "title": title.strip() or "No title", + "start": f"{start_date} {start_time}".strip() if start_time else "", + "end": f"{end_date} {end_time}".strip() if end_time else "", + "location": location.strip(), + } + ) self.events = all_events logger.info(f"[Calendar] Found {len(self.events)} events using subprocess")