Skip to content

Instantly share code, notes, and snippets.

@aaron-watts
Last active December 10, 2021 14:05
Show Gist options
  • Save aaron-watts/f18584427e1c95b8063267881a438945 to your computer and use it in GitHub Desktop.
Save aaron-watts/f18584427e1c95b8063267881a438945 to your computer and use it in GitHub Desktop.
To send iCalendar events for today to window managers notification tray
#!/usr/bin/env python3
from dotenv import dotenv_values
from icalevents.icalevents import events as ical_events
from datetime import date, datetime
from os import system as shell
from os import path
import subprocess
from time import sleep
def connection():
try:
return subprocess.run(
['wget', '-q', '--spider', 'google.com'],
timeout = 3
).returncode == 0
except subprocess.TimeoutExpired:
return False
def pipe_events():
dir_path = path.dirname(path.realpath(__file__))
config = dotenv_values(f'{dir_path}/.env')
today = date.today()
yy, mm, dd = today.year, today.month, today.day
today_start = datetime( yy, mm, dd )
today_end = datetime( yy, mm, dd+1 )
try:
for cal in config:
cal_events = ical_events(
url=config[cal],
start=today_start,
end=today_end
)
for evt in cal_events:
evtstr = str(evt)
evt_time = evtstr[11:16]
evt_info = evtstr[27:]
shell(
f'notify-send -a Calendar "{evt_time} {cal.capitalize()}" "{evt_info}"'
)
shell(f'echo "{datetime.now()} iCal Notification Success" >>/tmp/my_script.out')
except:
shell('echo "{datetime.now()} iCal Notification Fail" >>/tmp/my_script.out')
if __name__ == "__main__":
connected = False
while not connected:
sleep(15)
if connection():
connected = True
pipe_events()
@aaron-watts
Copy link
Author

Regolith Calendar Notifications : Usage

Place script in arbitray location i.e. ~/Documents/Scripts/Regolith/. Within same directory create a file named .env and populate it with iCal links like so:

main=some-url.ical
birthdays=some-other-url.ical

Make script executable with chmod u+x regolith_icalendar_notify.py

In file ~/.config/regolith/Xresources and the following line:

i3-wm.program.1: /home/user/path/to/script/regolith_icalendar_notify.py

NOTE If you are already using the key i3-wm.program.1 then change to an appropriate number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment