-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventReminders.py
66 lines (52 loc) · 1.96 KB
/
EventReminders.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
#
# Cole Smith
# Event Reminder for Tech@NYU
# EventReminders.py
#
import os
import datetime
import EventGrabber
import SlackInterpreter
# TODO: Check for events that happened two days ago
API_URL = "https://api.tnyu.org/v3"
def update_queue(notification_queue, days):
"""
Appends found events to notification_queue
:param notification_queue: An Array of Events
:param days: The days prior to event in which to remind the user
:return: notification_queue
"""
event_grabber = EventGrabber.EventGrabber(API_URL, str(os.environ["TNYU_API_KEY"]))
upcoming_events = event_grabber.get_list_of_upcoming_events()
for e in upcoming_events:
time_from_today = datetime.date.today() + datetime.timedelta(days=days)
if e.start_time.date() == time_from_today:
print str(datetime.date.today()) + " : Event found for " + str(e.start_time.date()) + " : " + e.title
notification_queue.append(e)
return notification_queue
def notify_users(notification_queue):
"""
Sends Notifications to users from the notification_queue
:param notification_queue: An array of Events
:return: None
"""
for n in notification_queue:
name_parts = n.creator.split()
user = slack_interpreter.find_user_by_full_name(name_parts[0], name_parts[1])
message = "Hello! This is a reminder that you have an event coming up, " + \
n.title + " on " + str(n.start_time)
slack_interpreter.send_message_to_user(user, message)
if n.errors:
errors = ""
for e in n.errors:
errors += e + " "
else:
errors = "No errors found with event"
slack_interpreter.send_message_to_user(user, errors)
if __name__ == '__main__':
slack_interpreter = SlackInterpreter.SlackInterpreter()
slack_interpreter.connect()
queue = []
queue = update_queue(queue, 7)
queue = update_queue(queue, 2)
notify_users(queue)