fix: use khal 0.11.3 command
This commit is contained in:
+26
-16
@@ -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,17 +155,27 @@ 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:
|
||||
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")
|
||||
self.emit_events_changed(self.events)
|
||||
|
||||
Reference in New Issue
Block a user