dotfiles/dot_config/waybar/executable_waybar-khal.py

36 lines
937 B
Python
Raw Normal View History

2023-05-31 09:44:30 +02:00
#!/usr/bin/env python
2023-06-28 08:43:28 +02:00
2023-05-31 09:44:30 +02:00
import subprocess
2023-06-28 08:43:28 +02:00
import datetime
import json
from html import escape
2023-05-31 09:44:30 +02:00
data = {}
2023-06-28 08:43:28 +02:00
today = datetime.date.today().strftime("%Y-%m-%d")
next_week = (datetime.date.today() +
datetime.timedelta(days=10)).strftime("%Y-%m-%d")
#output = subprocess.check_output("khal list now "+next_week, shell=True)
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-06-28 08:43:28 +02:00
#output = output.decode("utf-8")
2023-05-31 09:44:30 +02:00
lines = output.split("\n")
new_lines = []
for line in lines:
2023-06-28 08:43:28 +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-06-28 08:43:28 +02:00
if today in output:
2023-05-31 09:44:30 +02:00
data['text'] = "" + output.split('\n')[1]
else:
data['text'] = ""
2023-06-28 08:43:28 +02:00
2023-05-31 09:44:30 +02:00
data['tooltip'] = output
2023-06-28 08:43:28 +02:00
2023-05-31 09:44:30 +02:00
print(json.dumps(data))