-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·72 lines (56 loc) · 1.89 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
import environment
from yaml import safe_load
from threading import Event
from assistant import AssistantWindow
from notify2 import init, Notification
from utility import timeNow, weekDayToday
from multiprocessing import Process, set_start_method
""" global declarations """
dataFile = 'data.yaml'
attendeeName = 'User' # attendee's name
meetings = {} # stores meeting objects indexed by meeting time
def readData():
""" reads the attendee name & meetings schedule from `data.json` """
global attendeeName, meetings
with open(dataFile) as yamlData:
data = safe_load(yamlData)
attendeeName = data['attendee-name']
meetings = data['meetings']
def notify(meeting):
""" generates meeting notification """
init('Meetings Assistant')
Notification(
summary='Meeting Reminder',
message=meeting['name']
).show()
# driver
if __name__ == "__main__":
set_start_method('fork')
""" Interval Loop:
checks for meetings every minute and
launches meeting assistant if one is
scheduled for the current time & day
"""
e = Event()
interval = 60 # sec
while not e.wait(interval):
# read data.json
readData()
t = timeNow()
d = weekDayToday()
for meeting in meetings:
if t == meeting['time'] and (
(type(meeting['days']) == list and d in meeting['days'])
or (type(meeting['days']) == str and meeting['days'].lower() == 'everyday')
):
# notify about the meeting
notify(meeting)
# start AssistantWindow as a new process
aw = Process(
target=AssistantWindow,
args=(meeting, attendeeName)
)
aw.start()
aw.join() # wait for assistant window to terminate
break