-
Notifications
You must be signed in to change notification settings - Fork 0
/
icanical_main.py
48 lines (39 loc) · 1.68 KB
/
icanical_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
"""
The ican ical main which ties together the controller, model, and view.
"""
import icanical_controller
import icanical_model
import icanical_view
from send_error_mail import send_error_mail
def main():
"""
Takes a username and password for an email account to use as a bot.
The bot account will reply to any new email in its inbox with an ical
invite to an event located in the text of the email. Nothing is returned
by main.
"""
username = input("Enter a Bot Email Username: ")
password = input("Enter a Bot Email Password: ")
while True:
# starting the controller makes the bot start waiting for a new email
controller = icanical_controller.Controller()
controller.check_inbox(username, password)
# Once an email is received, try the rest of the code
try:
# extract the start time from the email
start_time = controller.datetimes()[0]
# extract the end time from the email
end_time = controller.datetimes()[1]
# plug in all of the extracted parameters into the model so the
# view can access them
event = icanical_model.Model(
controller.header, start_time, end_time, controller.recipient)
# the view uses the extracted parameters so create an ical file
view = icanical_view.View(event, username, password)
# send an email with the ical attached
view.send_ical()
except: # pylint: disable=bare-except
# if the code fails in any way, send an error email
send_error_mail(controller.recipient, username, password)
if __name__ == "__main__":
main()