waybar: more improvements to waybar_khal

This commit is contained in:
Konstantin Koslowski 2021-05-12 07:37:35 +02:00
parent 70b63af2ce
commit e4623831ab

View file

@ -4,6 +4,8 @@ from datetime import date, datetime, timedelta
import json
from html import escape
TEXT_MAX_LEN = 40
today = date.today().strftime("%Y-%m-%d")
days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Today",
"Tomorrow" ]
@ -17,9 +19,9 @@ start = subprocess.check_output("khal list --format \"{start}\" now "+next_week,
end = subprocess.check_output("khal list --format \"{end}\" now "+next_week,
shell=True).decode("UTF-8").split("\n")
text = ""
text = "-"
tooltip = ""
alt = "idle"
event = "-"
for i in range(len(title)):
t = escape(title[i])
s = escape(start[i])
@ -47,18 +49,22 @@ for i in range(len(title)):
## ongoing
if ts_start < ts_now:
if ts_start < ts_now and ts_now < ts_end:
event = f"{t}"
text = f"{t_start[1]} - {t_end[1]} {t}"
alt = "now"
## upcoming
elif event == "-":
event = f"{t}"
elif text == "-":
text = f"{t_start[1]} - {t_end[1]} {t}"
alt = "today"
line = f"{t_start[1]} - {t_end[1]}: {t}"
text += f"\n{line}"
tooltip += f"\n{line}"
data = {}
data["text"] = event
if len(text) > TEXT_MAX_LEN:
text = f"{text[0:TEXT_MAX_LEN]}"
data["text"] = text
data["alt"] = alt
data["tooltip"] = text
data["tooltip"] = tooltip
print(json.dumps(data))