waybar: add calendar with khal, fmt formatting

This commit is contained in:
Konstantin Koslowski 2021-05-08 22:22:08 +02:00
parent 2f419e1760
commit eaeed6ab5b
4 changed files with 81 additions and 26 deletions

37
bin/waybar_khal.py Executable file
View 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))

View file

@ -30,6 +30,7 @@
"custom/separator#right",
"battery",
"custom/separator#right",
"custom/calendar",
"clock",
"tray"
],
@ -39,6 +40,16 @@
"custom/separator#right": {
"format": " <span foreground='#268bd2'></span> "
},
"custom/calendar": {
"format": "{}",
"tooltip-format": "{}",
"tooltip": true,
"return-type": "json",
"interval": 300,
"escape": false,
"exec": "$HOME/.config/sway/bin/waybar_khal.py 2> /dev/null",
"on-click": "foot -T float khal interactive"
},
"custom/mail": {
"format": "{icon} {}",
"return-type": "json",
@ -60,21 +71,19 @@
"format-icons": {
"chromium": " ",
"firefox": " ",
"Plexamp": "",
"default": " "
"Plexamp": "",
"default": " "
},
"escape": true,
"exec": "$HOME/.config/sway/bin/waybar_mediaplayer.py 2> /dev/null",
"exec-if": "pgrep plexamp"
},
"clock": {
"format": "<span foreground='#ebdbb2'> </span>{:%a, %d %b <span foreground='#ebdbb2'> </span>%H:%M}",
"tooltip-format": "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>",
"format": "<span foreground='#ebdbb2'> </span>{:%H:%M}",
"on-click": "foot -T float khal interactive"
},
"cpu": {
"format": "<span foreground='#ebdbb2'></span> {usage}%",
"format": "<span foreground='#ebdbb2'></span> {usage:3}%",
"states": {
"warning": 70,
"critical": 90
@ -90,7 +99,7 @@
"on-click": "foot -T float bashtop"
},
"backlight": {
"format": "<span foreground='#ebdbb2'>{icon}</span> {percent}%",
"format": "<span foreground='#ebdbb2'>{icon}</span> {percent:3}%",
"format-icons": [""]
},
"battery": {
@ -100,15 +109,15 @@
"warning": 30,
"critical": 15
},
"format": "<span foreground='#ebdbb2'>{icon}</span> {capacity}%",
"format-charging": "<span foreground='#268bd2'></span> {capacity}%",
"format": "<span foreground='#ebdbb2'>{icon}</span> {capacity:3}%",
"format-charging": "<span foreground='#268bd2'></span> {capacity:3}%",
"format-icons": ["", "", "", "", ""]
},
"network#wl0": {
"interval": 2,
"interface": "wl0",
"format": "{ifname}",
"format-wifi": "<span foreground='#ebdbb2'> </span>{ifname} {essid} ({signalStrength}%)",
"format-wifi": "<span foreground='#ebdbb2'> </span>{ifname} {essid} ({signalStrength:3}%)",
"format-ethernet": "<span foreground='#ebdbb2'> </span>{ifname}",
"format-linked": "<span foreground='#ebdbb2'> </span>{ifname}",
"format-disconnected": "<span foreground='#606060'></span>{ifname}",
@ -121,7 +130,7 @@
"interval": 2,
"interface": "en0",
"format": "{ifname}",
"format-wifi": "<span foreground='#ebdbb2'> </span> {essid} ({signalStrength}%)",
"format-wifi": "<span foreground='#ebdbb2'> </span> {essid} ({signalStrength:3}%)",
"format-ethernet": "<span foreground='#ebdbb2'> </span>{ifname}",
"format-linked": "<span foreground='#ebdbb2'> </span>{ifname}",
"format-disconnected": "<span foreground='#606060'></span>{ifname}",
@ -134,7 +143,7 @@
"interval": 2,
"interface": "vpn0",
"format": "{ifname}",
"format-wifi": "<span foreground='#ebdbb2'> </span> {essid} ({signalStrength}%)",
"format-wifi": "<span foreground='#ebdbb2'> </span> {essid} ({signalStrength:3}%)",
"format-ethernet": "<span foreground='#ebdbb2'> </span>{ifname}",
"format-linked": "<span foreground='#ebdbb2'> </span>{ifname}",
"format-disconnected": "<span foreground='#606060'></span>{ifname}",

View file

@ -27,6 +27,7 @@
"custom/separator#right",
"backlight",
"custom/separator#right",
"custom/calendar",
"clock",
"tray"
],
@ -36,6 +37,16 @@
"custom/separator#right": {
"format": " <span foreground='#268bd2'></span> "
},
"custom/calendar": {
"format": "{}",
"tooltip-format": "{}",
"tooltip": true,
"return-type": "json",
"interval": 300,
"escape": false,
"exec": "$HOME/.config/sway/bin/waybar_khal.py 2> /dev/null",
"on-click": "foot -T float khal interactive"
},
"custom/mail": {
"format": "{icon} {}",
"return-type": "json",
@ -57,21 +68,19 @@
"format-icons": {
"chromium": " ",
"firefox": " ",
"Plexamp": "",
"default": " "
"Plexamp": "",
"default": " "
},
"escape": true,
"exec": "$HOME/.config/sway/bin/waybar_mediaplayer.py 2> /dev/null",
"exec-if": "pgrep plexamp"
},
"clock": {
"format": "<span foreground='#ebdbb2'> </span>{:%a, %d %b <span foreground='#ebdbb2'> </span>%H:%M}",
"tooltip-format": "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>",
"format": "<span foreground='#ebdbb2'> </span>{:%H:%M}",
"on-click": "foot -T float khal interactive"
},
"cpu": {
"format": "<span foreground='#ebdbb2'></span> {usage}%",
"format": "<span foreground='#ebdbb2'></span> {usage:3}%",
"states": {
"warning": 70,
"critical": 90
@ -87,7 +96,7 @@
"on-click": "foot -T float bashtop"
},
"backlight": {
"format": "<span foreground='#ebdbb2'>{icon}</span> {percent}%",
"format": "<span foreground='#ebdbb2'>{icon}</span> {percent:3}%",
"format-icons": [""]
},
"battery": {
@ -97,15 +106,15 @@
"warning": 30,
"critical": 15
},
"format": "<span foreground='#ebdbb2'>{icon}</span> {capacity}%",
"format-charging": "<span foreground='#268bd2'></span> {capacity}%",
"format": "<span foreground='#ebdbb2'>{icon}</span> {capacity:3}%",
"format-charging": "<span foreground='#268bd2'></span> {capacity:3}%",
"format-icons": ["", "", "", "", ""]
},
"network#wl0": {
"interval": 2,
"interface": "wl0",
"format": "{ifname}",
"format-wifi": "<span foreground='#ebdbb2'> </span>{ifname} {essid} ({signalStrength}%)",
"format-wifi": "<span foreground='#ebdbb2'> </span>{ifname} {essid} ({signalStrength:3}%)",
"format-ethernet": "<span foreground='#ebdbb2'> </span>{ifname}",
"format-linked": "<span foreground='#ebdbb2'> </span>{ifname}",
"format-disconnected": "<span foreground='#606060'></span>{ifname}",
@ -118,7 +127,7 @@
"interval": 2,
"interface": "en0",
"format": "{ifname}",
"format-wifi": "<span foreground='#ebdbb2'> </span> {essid} ({signalStrength}%)",
"format-wifi": "<span foreground='#ebdbb2'> </span> {essid} ({signalStrength:3}%)",
"format-ethernet": "<span foreground='#ebdbb2'> </span>{ifname}",
"format-linked": "<span foreground='#ebdbb2'> </span>{ifname}",
"format-disconnected": "<span foreground='#606060'></span>{ifname}",
@ -131,7 +140,7 @@
"interval": 2,
"interface": "vpn0",
"format": "{ifname}",
"format-wifi": "<span foreground='#ebdbb2'> </span> {essid} ({signalStrength}%)",
"format-wifi": "<span foreground='#ebdbb2'> </span> {essid} ({signalStrength:3}%)",
"format-ethernet": "<span foreground='#ebdbb2'> </span>{ifname}",
"format-linked": "<span foreground='#ebdbb2'> </span>{ifname}",
"format-disconnected": "<span foreground='#606060'></span>{ifname}",

View file

@ -9,8 +9,8 @@
* {
border: none;
border-radius: 0;
font-family: Input, "Font Awesome 5 Free";
font-size: 13px;
font-family: "Cascadia Code PL Regular";
font-size: 12px;
min-height: 0;
}