waybar: add start/end times to calendar, general improvements
This commit is contained in:
parent
3ddba3831d
commit
b6180db9f6
2 changed files with 38 additions and 20 deletions
|
@ -12,26 +12,40 @@ days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Su
|
|||
|
||||
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")
|
||||
title = subprocess.check_output("khal list --format \"{title}\" now "+next_week,
|
||||
shell=True).decode("UTF-8").split("\n")
|
||||
start = subprocess.check_output("khal list --format \"{start}\" now "+next_week,
|
||||
shell=True).decode("UTF-8").split("\n")
|
||||
end = subprocess.check_output("khal list --format \"{end}\" now "+next_week,
|
||||
shell=True).decode("UTF-8").split("\n")
|
||||
|
||||
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()
|
||||
lines = ""
|
||||
for i in range(len(title)):
|
||||
t = escape(title[i])
|
||||
s = escape(start[i])
|
||||
e = escape(end[i])
|
||||
line = ""
|
||||
if len(t) and t.split(",")[0] in days:
|
||||
line = f"\n<b>{t}</b>"
|
||||
else:
|
||||
ss = s.split(" ")
|
||||
es = e.split(" ")
|
||||
if len(es) == 1 or len(ss) == 1:
|
||||
line = f"<i>{t}</i>"
|
||||
else:
|
||||
line = f"{ss[1]} - {es[1]}: {t}"
|
||||
|
||||
today_text = datetime.date.today().strftime("%a, %d %b")
|
||||
if today in output:
|
||||
event = output.split('\n')[1]
|
||||
data['text'] = f" {today_text}: {event}"
|
||||
lines += f"{line}\n"
|
||||
|
||||
if today in lines:
|
||||
event = lines.split('\n')[2]
|
||||
if len(event) > 30:
|
||||
event = f"{event[0:30]}…"
|
||||
data["text"] = f"{event}"
|
||||
data["alt"] = "event"
|
||||
else:
|
||||
data['text'] = f" {today_text}"
|
||||
|
||||
data['tooltip'] = output
|
||||
data["text"] = "-"
|
||||
data["alt"] = "idle"
|
||||
data["tooltip"] = lines
|
||||
|
||||
print(json.dumps(data))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue