waybar: add calendar with khal, fmt formatting
This commit is contained in:
parent
2f419e1760
commit
eaeed6ab5b
4 changed files with 81 additions and 26 deletions
37
bin/waybar_khal.py
Executable file
37
bin/waybar_khal.py
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env python
|
||||
import subprocess
|
||||
import datetime
|
||||
import json
|
||||
from html import escape
|
||||
|
||||
data = {}
|
||||
|
||||
today = datetime.date.today().strftime("%Y-%m-%d")
|
||||
days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Today",
|
||||
"Tomorrow" ]
|
||||
|
||||
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")
|
||||
|
||||
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}"
|
||||
else:
|
||||
data['text'] = f" {today_text}"
|
||||
|
||||
data['tooltip'] = output
|
||||
|
||||
print(json.dumps(data))
|
Loading…
Add table
Add a link
Reference in a new issue