dotfiles/dot_config/waybar/executable_waybar-khal.py

28 lines
663 B
Python
Raw Normal View History

2023-05-31 09:44:30 +02:00
#!/usr/bin/env python
2023-07-03 09:33:03 +02:00
2023-06-28 08:43:28 +02:00
import json
2023-07-02 03:08:41 +02:00
import subprocess
2023-07-03 09:33:03 +02:00
from html import escape
2023-05-31 09:44:30 +02:00
data = {}
2023-07-03 09:33:03 +02:00
2023-05-31 09:44:30 +02:00
output = subprocess.check_output("khal list now 7days --format \"{start-end-time-style} {title}\"", shell=True).decode("utf-8")
2023-07-03 09:33:03 +02:00
2023-05-31 09:44:30 +02:00
lines = output.split("\n")
new_lines = []
for line in lines:
2023-07-03 09:33:03 +02:00
clean_line = escape(line).split(" ::")[0]
if len(clean_line) and not clean_line[0] in ['0', '1', '2']:
clean_line = "\n<b>"+clean_line+"</b>"
new_lines.append(clean_line)
2023-05-31 09:44:30 +02:00
output = "\n".join(new_lines).strip()
2023-07-03 09:33:03 +02:00
2023-07-02 03:08:41 +02:00
if "Today" in output:
2023-05-31 09:44:30 +02:00
data['text'] = "" + output.split('\n')[1]
else:
data['text'] = ""
2023-07-03 09:33:03 +02:00
2023-05-31 09:44:30 +02:00
data['tooltip'] = output
2023-07-03 09:33:03 +02:00
2023-05-31 09:44:30 +02:00
print(json.dumps(data))