-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudfunction.py
More file actions
137 lines (91 loc) · 3.36 KB
/
Copy pathcloudfunction.py
File metadata and controls
137 lines (91 loc) · 3.36 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import json
from classes import Event, Participant
import smtplib
import sys
def lambda_handler(event, context):
eventObject=JSONtoEvent(event)
if len(eventObject.participants)==eventObject.min:
sendEmail(eventObject)
elif len(eventObject.participants) > eventObject.min:
sendEmailToLast(eventObject)
#convert JSON to Event
def JSONtoEvent(j: json):
event= Event(j["min"], j["max"], j["Location"], j["Time"], j["Title"], j["Description"])
persons=[]
for participant in j["Participants"].values():
print(participant["Email"])
persons.append(Participant(participant["Email"], participant["Name"]))
event.addParticipants(persons)
print(persons)
return event
def sendEmailToLast(event):
sender_email = 'frisboysproject@gmail.com'
password = 'amherst123'
participants=event.participants
receiver_emails = []
receiver_emails.append(participants[-1].getEmail())
names=[]
for p in participants:
names.append(p.getName())
# Email text
email_body = '''Subject: Your Hangout Event\n
\nHello, you have an update from Hangout!
'''
email_body+=('\nYour event is on!\n\n' +"\nTime: "+event.time+ "\nTitle: " + event.title + "\nDescription: " + event.description+ "\nLocation: " + event.location +"\n\nParticipants:\n")
for count, name in enumerate(names):
email_body+=("\n"+str(count+1)+". "+ name)
email_body += ("\n\n\nSee you there!")
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(sender_email, password)
# Sending email from sender, to receiver with the email body
server.sendmail(sender_email, receiver_emails, email_body)
print('Email sent!')
print('Closing the server...')
server.quit()
#SEND THE EMAIL
def sendEmail(event):
sender_email = 'frisboysproject@gmail.com'
password = 'amherst123'
participants=event.participants
receiver_emails = []
for p in participants:
receiver_emails.append(p.getEmail())
names=[]
for p in participants:
names.append(p.getName())
# Email text
email_body = '''Subject: Your Hangout Event\n
\nHello, you have an update from Hangout!
'''
email_body+=('\nYour event is on!\n\n' +"\nTime: "+event.time+ "\nTitle: " + event.title + "\nDescription: " + event.description+ "\nLocation: " + event.location +"\n\nParticipants:\n")
for count, name in enumerate(names):
email_body+=("\n"+str(count+1)+". "+ name)
email_body += ("\n\n\nSee you there!")
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(sender_email, password)
# Sending email from sender, to receiver with the email body
server.sendmail(sender_email, receiver_emails, email_body)
print('Email sent!')
print('Closing the server...')
server.quit()
return "successs!!!!"
#DETERMINE FROM JSON if minpart is reached
def greaterThanMin(j: json):
jParsed = json.loads(j)
if len(jParsed["Participants"]) >= int(jParsed["min"]):
sendEmail(JSONtoEvent(j))
return True
else:
return False
def lessThanMax(j: json):
jParsed = json.loads(j)
if len(jParsed["Participants"]) <= int(jParsed["max"]):
return True
else:
return False