waybar: more improvements to waybar_khal
This commit is contained in:
parent
70b63af2ce
commit
e4623831ab
1 changed files with 14 additions and 8 deletions
|
@ -4,6 +4,8 @@ from datetime import date, datetime, timedelta
|
||||||
import json
|
import json
|
||||||
from html import escape
|
from html import escape
|
||||||
|
|
||||||
|
TEXT_MAX_LEN = 40
|
||||||
|
|
||||||
today = date.today().strftime("%Y-%m-%d")
|
today = 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" ]
|
||||||
|
@ -17,9 +19,9 @@ 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")
|
||||||
|
|
||||||
text = ""
|
text = "-"
|
||||||
|
tooltip = ""
|
||||||
alt = "idle"
|
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])
|
||||||
|
@ -47,18 +49,22 @@ for i in range(len(title)):
|
||||||
## ongoing
|
## ongoing
|
||||||
if ts_start < ts_now:
|
if ts_start < ts_now:
|
||||||
if ts_start < ts_now and ts_now < ts_end:
|
if ts_start < ts_now and ts_now < ts_end:
|
||||||
event = f"{t}"
|
text = f"{t_start[1]} - {t_end[1]} {t}"
|
||||||
alt = "now"
|
alt = "now"
|
||||||
## upcoming
|
## upcoming
|
||||||
elif event == "-":
|
elif text == "-":
|
||||||
event = f"{t}"
|
text = f"{t_start[1]} - {t_end[1]} {t}"
|
||||||
alt = "today"
|
alt = "today"
|
||||||
line = f"{t_start[1]} - {t_end[1]}: {t}"
|
line = f"{t_start[1]} - {t_end[1]}: {t}"
|
||||||
text += f"\n{line}"
|
tooltip += f"\n{line}"
|
||||||
|
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
data["text"] = event
|
|
||||||
|
if len(text) > TEXT_MAX_LEN:
|
||||||
|
text = f"{text[0:TEXT_MAX_LEN]}…"
|
||||||
|
data["text"] = text
|
||||||
data["alt"] = alt
|
data["alt"] = alt
|
||||||
data["tooltip"] = text
|
data["tooltip"] = tooltip
|
||||||
|
|
||||||
print(json.dumps(data))
|
print(json.dumps(data))
|
||||||
|
|
Loading…
Reference in a new issue