dotfiles/dot_config/waybar/executable_waybar-khal.py

34 lines
829 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-07-03 09:39:20 +02:00
import datetime
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-07-03 09:39:20 +02:00
today = datetime.date.today().strftime("%Y-%m-%d")
2023-07-03 09:43:42 +02:00
next_week = (datetime.date.today() +
datetime.timedelta(days=10)).strftime("%Y-%m-%d")
output = subprocess.check_output("khal list now " + next_week + " --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]
2023-07-03 09:54:25 +02:00
if len(clean_line) and clean_line[0].isalpha():
2023-07-03 09:33:03 +02:00
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-03 09:39:20 +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))