waybar: beautify waybar_khal, add ongoing events
This commit is contained in:
parent
b6180db9f6
commit
451cd1e2c7
2 changed files with 37 additions and 23 deletions
|
@ -1,16 +1,14 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import subprocess
|
import subprocess
|
||||||
import datetime
|
from datetime import date, datetime, timedelta
|
||||||
import json
|
import json
|
||||||
from html import escape
|
from html import escape
|
||||||
|
|
||||||
data = {}
|
today = date.today().strftime("%Y-%m-%d")
|
||||||
|
|
||||||
today = datetime.date.today().strftime("%Y-%m-%d")
|
|
||||||
days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Today",
|
days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Today",
|
||||||
"Tomorrow" ]
|
"Tomorrow" ]
|
||||||
|
|
||||||
next_week = (datetime.date.today() + datetime.timedelta(days=10)).strftime("%Y-%m-%d")
|
next_week = (date.today() + timedelta(days=10)).strftime("%Y-%m-%d")
|
||||||
|
|
||||||
title = subprocess.check_output("khal list --format \"{title}\" now "+next_week,
|
title = subprocess.check_output("khal list --format \"{title}\" now "+next_week,
|
||||||
shell=True).decode("UTF-8").split("\n")
|
shell=True).decode("UTF-8").split("\n")
|
||||||
|
@ -19,33 +17,48 @@ start = subprocess.check_output("khal list --format \"{start}\" now "+next_week,
|
||||||
end = subprocess.check_output("khal list --format \"{end}\" now "+next_week,
|
end = subprocess.check_output("khal list --format \"{end}\" now "+next_week,
|
||||||
shell=True).decode("UTF-8").split("\n")
|
shell=True).decode("UTF-8").split("\n")
|
||||||
|
|
||||||
lines = ""
|
text = ""
|
||||||
|
alt = "idle"
|
||||||
|
event = "-"
|
||||||
for i in range(len(title)):
|
for i in range(len(title)):
|
||||||
t = escape(title[i])
|
t = escape(title[i])
|
||||||
s = escape(start[i])
|
s = escape(start[i])
|
||||||
e = escape(end[i])
|
e = escape(end[i])
|
||||||
line = ""
|
line = ""
|
||||||
|
## header
|
||||||
if len(t) and t.split(",")[0] in days:
|
if len(t) and t.split(",")[0] in days:
|
||||||
line = f"\n<b>{t}</b>"
|
line = f"\n<b>{t}</b>"
|
||||||
|
## event
|
||||||
else:
|
else:
|
||||||
ss = s.split(" ")
|
t_start = s.split(" ")
|
||||||
es = e.split(" ")
|
t_end = e.split(" ")
|
||||||
if len(es) == 1 or len(ss) == 1:
|
## all day
|
||||||
|
if len(t_start) == 1 or len(t_end) == 1:
|
||||||
line = f"<i>{t}</i>"
|
line = f"<i>{t}</i>"
|
||||||
|
## start - end
|
||||||
else:
|
else:
|
||||||
line = f"{ss[1]} - {es[1]}: {t}"
|
ts_start = datetime.timestamp(datetime.strptime(s, '%Y-%m-%d %H:%M'))
|
||||||
|
ts_end = datetime.timestamp(datetime.strptime(e, '%Y-%m-%d %H:%M'))
|
||||||
|
ts_now = datetime.timestamp(datetime.now())
|
||||||
|
## today
|
||||||
|
if t_start[0] == today:
|
||||||
|
## upcoming or ongoing
|
||||||
|
if ts_now < ts_end:
|
||||||
|
## ongoing
|
||||||
|
if ts_start < ts_now:
|
||||||
|
if ts_start < ts_now and ts_now < ts_end:
|
||||||
|
event = f"{t}"
|
||||||
|
alt = "now"
|
||||||
|
## upcoming
|
||||||
|
elif event == "-":
|
||||||
|
event = f"{t}"
|
||||||
|
alt = "today"
|
||||||
|
line = f"{t_start[1]} - {t_end[1]}: {t}"
|
||||||
|
text += f"\n{line}"
|
||||||
|
|
||||||
lines += f"{line}\n"
|
data = {}
|
||||||
|
data["text"] = event
|
||||||
if today in lines:
|
data["alt"] = alt
|
||||||
event = lines.split('\n')[2]
|
data["tooltip"] = text
|
||||||
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))
|
print(json.dumps(data))
|
||||||
|
|
|
@ -47,7 +47,8 @@
|
||||||
"return-type": "json",
|
"return-type": "json",
|
||||||
"interval": 300,
|
"interval": 300,
|
||||||
"format-icons": {
|
"format-icons": {
|
||||||
"event": "<span foreground='#b8bb26'></span> ",
|
"now": "<span foreground='#fb4934'></span> ",
|
||||||
|
"today": "<span foreground='#b8bb26'></span> ",
|
||||||
"idle": " "
|
"idle": " "
|
||||||
},
|
},
|
||||||
"escape": false,
|
"escape": false,
|
||||||
|
|
Loading…
Reference in a new issue