calendar widget

auto-flake-update
Yorick van Pelt 2022-04-16 09:59:10 +02:00
parent 5bea35ade1
commit c1c4b77278
Signed by: yorick
GPG Key ID: A36E70F9DC014A15
5 changed files with 123 additions and 2 deletions

91
bin/cal.py Executable file
View File

@ -0,0 +1,91 @@
#!/usr/bin/env nix-shell
#!nix-shell -p python3 -p gcalcli -p python3.pkgs.i3ipc -i python3
#bin.y-cal-widget
from gcalcli.gcal import GoogleCalendarInterface
from datetime import datetime, timedelta
from collections import namedtuple
from gcalcli.cli import parse_cal_names
from dateutil.tz import tzlocal
import json
import subprocess
import sys
import i3ipc
from pathlib import Path
if not Path("~/.gcalcli_oauth").expanduser().exists():
print(json.dumps({"text": "run gcalcli"}))
sys.exit(0)
i3 = i3ipc.Connection()
gcal = GoogleCalendarInterface(
cal_names=parse_cal_names(["yorickvanpelt@gmail.com", "yorick.vanpelt@tweag.io"]),
config_folder=None, refresh_cache=False,
use_cache=True,
ignore_started=False,
ignore_declined=True,
color_date="yellow",
override_color=False,
military=True,
#tsv=True,
)
start_date = datetime.now(tzlocal())
events = gcal._search_for_events(start=datetime.now(tzlocal()), end=start_date + timedelta(days=1), search_text=None)
opt = sys.argv[1]
def authuser(evt):
if evt["gcalcli_cal"]["id"] == "yorickvanpelt@gmail.com":
return 0
else:
return 1
def tooltip(evt):
# todo: location
return f"""
<b>{evt["summary"]}</b>
{evt["s"].strftime("%b %d %H:%M")} - {evt["e"].strftime("%H:%M")}
"""
def click(evt):
# todo: only on certain time before
if 'hangoutLink' in evt:
# jump into video call
url = evt["hangoutLink"] + "?authuser=" + str(authuser(evt))
subprocess.call(["playerctl", "pause"])
i3.command("focus output 'DVI-D-1', workspace --no-auto-back-and-forth 9")
subprocess.call(["chromium", url])
else:
subprocess.call(["xdg-open", evt["htmlLink"]])
def rightclick(evt):
subprocess.call(["xdg-open", "https://calendar.google.com"])
events = [e for e in events if not gcal._DeclinedEvent(e)]
if opt == "dump":
print(json.dumps(events, default=str))
if opt == "click":
click(events[0])
if opt == "rightclick":
rightclick(events[0])
if opt == "tooltip":
print(tooltip(events[0]))
if opt == "list": # todo: rename to first
for evt in events:
icon = ""
# todo: tooltip
if 'hangoutLink' in evt:
icon = ""
print(json.dumps({
"text": evt["s"].strftime("%H:%M") + " " + evt["summary"] + " " + icon,
"class": f"user-{authuser(evt)}",
"tooltip": tooltip(evt)
}))
break

View File

@ -14,8 +14,16 @@ let
}
'';
};
makeWrap = cmd: executable: name:
pkgs.runCommand name { buildInputs = [ makeWrapper ]; } ''
makeWrapper ${executable} $out/bin/${name} --add-flags ${cmd}
'';
in lib.mapAttrs (k: f: f k) {
backup = compileShell ./backup.sh (with pkgs; [ utillinux duplicity ]);
screenshot_public =
compileShell ./screenshot_public.sh (with pkgs; [ scrot xclip rsync ]);
# impure
y-cal-widget = makeWrap (toString ./cal.py) "${
python3.withPackages (p: [ (p.toPythonModule gcalcli) p.i3ipc ])
}/bin/python";
}

View File

@ -211,5 +211,6 @@ in {
wl-clipboard
wldash
# zoom-us
bin.y-cal-widget
];
}

View File

@ -29,7 +29,7 @@ window#waybar {
border-bottom: 3px solid white;
}
#clock, #battery, #cpu, #memory, #network, #disk, #pulseaudio, #custom-spotify, #tray, #mode {
#clock, #battery, #cpu, #memory, #network, #disk, #pulseaudio, #custom-spotify, #tray, #mode, #custom-cal {
padding: 0 10px;
margin: 0 5px;
}
@ -97,6 +97,16 @@ window#waybar {
color: #2a5c45;
}
#custom-cal {
color: white;
}
#custom-cal.user-0 {
background: #4285f4;
}
#custom-cal.user-1 {
background: #f67755;
}
#tray {
background-color: #2980b9;
}

View File

@ -2,7 +2,7 @@ layer = "top"
height = 26
modules-left = [ "sway/workspaces", "sway/mode", "custom/spotify" ]
modules-center = [ "sway/window" ]
modules-right = [ "pulseaudio", "network", "disk", "battery", "clock", "tray" ]
modules-right = [ "custom/cal", "pulseaudio", "network", "disk", "battery", "clock", "tray" ]
["sway/workspaces"]
all-outputs = false
@ -20,6 +20,7 @@ urgent = ""
focused = ""
default = ""
["sway/mode"]
format = '<span style="italic">{}</span>'
@ -65,6 +66,16 @@ portable = ""
car = ""
default = [ "", "" ]
["custom/cal"]
format = "{}"
escape = true
max-length = 40
on-click = "y-cal-widget click"
on-click-right = "y-cal-widget rightclick"
exec = "y-cal-widget list"
interval = 120
return-type = "json"
["custom/spotify"]
format = "{}"
escape = true