-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_invitation.py
46 lines (37 loc) · 1.1 KB
/
send_invitation.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
import invitation
import requests
#Change URL
REQUEST_URL = 'INSERT URL TO YOUR SERVICE'
def get_list_mail_from_server ():
response = requests.get(REQUEST_URL)
print('Try to get list.........')
if(response.status_code == 200):
print('OK')
return response
else :
print('KO!!')
return None
def create_contact_list(json_obj):
contacts_list = []
for contact in json_obj:
contact = invitation.Contact(
contact['firstname'],
contact['lastname'],
contact['mail'],
contact['to_send'])
contacts_list.append(contact)
return contacts_list
def main():
#get list of contact from the server
response = get_list_mail_from_server()
if(response is not None):
print(response.text)
#create a list with Contact obj
contacts_list = create_contact_list(response.json())
print('Connetion to send mail.......')
email = invitation.Email()
#Send mail
email.send_mail(contacts_list)
else :
print('Error to get mail list')
main()