fix: use khal 0.11.3 command
This commit is contained in:
+27
-17
@@ -1,4 +1,3 @@
|
|||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
@@ -131,18 +130,19 @@ class CalendarService:
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
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 = [
|
cmd = [
|
||||||
khal_path,
|
khal_path,
|
||||||
"list",
|
"list",
|
||||||
"--json",
|
"--format",
|
||||||
"title",
|
"{start-date}{bell}{start-time}{bell}{end-date}{bell}{end-time}{bell}{title}{bell}{location}",
|
||||||
"--json",
|
"--day-format",
|
||||||
"start",
|
"",
|
||||||
"--json",
|
|
||||||
"end",
|
|
||||||
"--json",
|
|
||||||
"location",
|
|
||||||
"today",
|
"today",
|
||||||
|
"eod",
|
||||||
]
|
]
|
||||||
logger.info(f"[Calendar] Running command: {' '.join(cmd)}")
|
logger.info(f"[Calendar] Running command: {' '.join(cmd)}")
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
@@ -155,16 +155,26 @@ class CalendarService:
|
|||||||
logger.info(f"[Calendar] Command stderr: {result.stderr[:200]}...")
|
logger.info(f"[Calendar] Command stderr: {result.stderr[:200]}...")
|
||||||
|
|
||||||
if result.stdout.strip():
|
if result.stdout.strip():
|
||||||
lines = result.stdout.strip().split("\n")
|
|
||||||
all_events = []
|
all_events = []
|
||||||
|
|
||||||
for line in lines:
|
for line in result.stdout.splitlines():
|
||||||
if line.strip():
|
if not line.strip():
|
||||||
try:
|
continue
|
||||||
events = json.loads(line)
|
|
||||||
all_events.extend(events)
|
parts = line.split("\a", 5)
|
||||||
except json.JSONDecodeError:
|
if len(parts) != 6:
|
||||||
continue
|
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
|
self.events = all_events
|
||||||
logger.info(f"[Calendar] Found {len(self.events)} events using subprocess")
|
logger.info(f"[Calendar] Found {len(self.events)} events using subprocess")
|
||||||
|
|||||||
Reference in New Issue
Block a user