Last active
December 10, 2021 14:05
-
-
Save aaron-watts/f18584427e1c95b8063267881a438945 to your computer and use it in GitHub Desktop.
To send iCalendar events for today to window managers notification tray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:Make script executable with
chmod u+x regolith_icalendar_notify.py
In file
~/.config/regolith/Xresources
and the following line: