-
Notifications
You must be signed in to change notification settings - Fork 0
/
bdyreminder.py
52 lines (44 loc) · 1.15 KB
/
bdyreminder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import time
import os
import winsound
import sys
from plyer import notification
from collections import namedtuple
from icalendar import Calendar
DEFAULT_CAL = 'cal.ics'
Bday = namedtuple('Bday', 'name bday')
def get_birthdays(cal):
with open(cal, 'rb') as g:
gcal = Calendar.from_ical(g.read())
for component in gcal.walk():
if component.name == "VEVENT":
name = component.get('SUMMARY')
if not name:
continue
name = name.replace("'s birthday", "")
bday = component.get('DTSTART').dt
bday = bday.strftime('%m%d')
yield Bday(name=name, bday=bday)
def showMsg(msg):
notification.notify(
title='Birthday Reminder',
message= msg,
timeout = 15,
)
def checkTodaysBirthdays():
today = time.strftime('%m%d')
flag = 0
for bd in get_birthdays("cal.ics"):
if today in bd.bday:
flag =1
winsound.Beep(500,1500) # we can use these also print('\007') or print('\a') for beep sound
showMsg("Today: " + bd.name +"'s Birthday")
if flag == 0:
winsound.Beep(500,1500)
showMsg("No Birthdays Today!")
if __name__ == '__main__':
if len(sys.argv) < 2:
cal = DEFAULT_CAL
else:
cal = sys.argv[1]
checkTodaysBirthdays()