2021-05-08 22:22:08 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import subprocess
|
|
|
|
import datetime
|
|
|
|
import json
|
|
|
|
from html import escape
|
|
|
|
|
|
|
|
data = {}
|
|
|
|
|
|
|
|
today = datetime.date.today().strftime("%Y-%m-%d")
|
|
|
|
days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Today",
|
|
|
|
"Tomorrow" ]
|
|
|
|
|
|
|
|
next_week = (datetime.date.today() + datetime.timedelta(days=10)).strftime("%Y-%m-%d")
|
|
|
|
|
2021-05-10 10:13:22 +02:00
|
|
|
title = subprocess.check_output("khal list --format \"{title}\" now "+next_week,
|
|
|
|
shell=True).decode("UTF-8").split("\n")
|
|
|
|
start = subprocess.check_output("khal list --format \"{start}\" now "+next_week,
|
|
|
|
shell=True).decode("UTF-8").split("\n")
|
|
|
|
end = subprocess.check_output("khal list --format \"{end}\" now "+next_week,
|
|
|
|
shell=True).decode("UTF-8").split("\n")
|
|
|
|
|
|
|
|
lines = ""
|
|
|
|
for i in range(len(title)):
|
|
|
|
t = escape(title[i])
|
|
|
|
s = escape(start[i])
|
|
|
|
e = escape(end[i])
|
|
|
|
line = ""
|
|
|
|
if len(t) and t.split(",")[0] in days:
|
|
|
|
line = f"\n<b>{t}</b>"
|
|
|
|
else:
|
|
|
|
ss = s.split(" ")
|
|
|
|
es = e.split(" ")
|
|
|
|
if len(es) == 1 or len(ss) == 1:
|
|
|
|
line = f"<i>{t}</i>"
|
|
|
|
else:
|
|
|
|
line = f"{ss[1]} - {es[1]}: {t}"
|
|
|
|
|
|
|
|
lines += f"{line}\n"
|
|
|
|
|
|
|
|
if today in lines:
|
|
|
|
event = lines.split('\n')[2]
|
|
|
|
if len(event) > 30:
|
|
|
|
event = f"{event[0:30]}…"
|
|
|
|
data["text"] = f"{event}"
|
|
|
|
data["alt"] = "event"
|
2021-05-08 22:22:08 +02:00
|
|
|
else:
|
2021-05-10 10:13:22 +02:00
|
|
|
data["text"] = "-"
|
|
|
|
data["alt"] = "idle"
|
|
|
|
data["tooltip"] = lines
|
2021-05-08 22:22:08 +02:00
|
|
|
|
|
|
|
print(json.dumps(data))
|