waybar: add start/end times to calendar, general improvements

This commit is contained in:
Konstantin Koslowski 2021-05-10 10:13:22 +02:00
parent 3ddba3831d
commit b6180db9f6
2 changed files with 38 additions and 20 deletions

View file

@ -12,26 +12,40 @@ days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Su
next_week = (datetime.date.today() + datetime.timedelta(days=10)).strftime("%Y-%m-%d")
output = subprocess.check_output("khal list --format \"{title}\" now "+next_week, shell=True)
output = output.decode("utf-8")
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 = output.split("\n")
new_lines = []
for line in lines:
clean_line = escape(line).split(" ::")[0]
# bold headers
if len(clean_line) and clean_line.split(",")[0] in days:
clean_line = f"\n<b>{clean_line}</b>"
new_lines.append(clean_line)
output = "\n".join(new_lines).strip()
today_text = datetime.date.today().strftime("%a, %d %b")
if today in output:
event = output.split('\n')[1]
data['text'] = f"{today_text}: {event}"
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:
data['text'] = f"{today_text}"
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}"
data['tooltip'] = output
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"
else:
data["text"] = "-"
data["alt"] = "idle"
data["tooltip"] = lines
print(json.dumps(data))

View file

@ -41,11 +41,15 @@
"format": " <span foreground='#268bd2'></span> "
},
"custom/calendar": {
"format": "{}",
"format": "{icon} {}",
"tooltip-format": "{}",
"tooltip": true,
"return-type": "json",
"interval": 300,
"format-icons": {
"event": "<span foreground='#b8bb26'></span> ",
"idle": " "
},
"escape": false,
"exec": "$HOME/.config/sway/bin/waybar_khal.py 2> /dev/null",
"on-click": "foot -T float khal interactive"
@ -79,7 +83,7 @@
"exec-if": "pgrep plexamp"
},
"clock": {
"format": "<span foreground='#ebdbb2'> </span>{:%H:%M}",
"format": "<span foreground='#ebdbb2'> </span>{: %a, %b %d, %H:%M}",
"on-click": "foot -T float khal interactive"
},
"cpu": {