-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcouple_mixer_v2.py
More file actions
94 lines (72 loc) · 2.7 KB
/
couple_mixer_v2.py
File metadata and controls
94 lines (72 loc) · 2.7 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
from random import choice
import smtplib
from email.mime.text import MIMEText
class TheWonderCouple:
def __init__(self):
self.gifter_email = ''
self.gifted_email = ''
def setGloriousSettings(self, gifter_email, gifted_email):
self.gifter_email = gifter_email
self.gifted_email = gifted_email
class TheAwesomeCoupleMixer:
def __init__(self):
self.wonder_couples = []
def magicMixer(self, emails):
num_couples = len(emails)
gifters = range(num_couples)
gifteds = range(num_couples)
for email in emails:
gifter = gifted = choice(gifters)
gifters.remove(gifter)
while(gifter == gifted):
gifted = choice(gifteds)
gifteds.remove(gifted)
twc = TheWonderCouple()
gifter_email = emails[gifter]
gifted_email = emails[gifted]
twc.setGloriousSettings(gifter_email, gifted_email)
self.wonder_couples.append(twc)
def getWonderCouples(self):
return self.wonder_couples
class TheFabulousMailer:
def __init__(self, smtp_server, smtp_port, from_email, from_email_pwd, subject):
self.smtp_server = smtp_server
self.smtp_port = smtp_port
self.from_email = from_email
self.from_email_pwd = from_email_pwd
self.subject = subject
def performLegendarySending(self, wonder_couples):
server = smtplib.SMTP(self.smtp_server, self.smtp_port)
server.ehlo()
server.starttls()
server.ehlo()
server.login(self.from_email, self.from_email_pwd)
for wonder_couple in wonder_couples:
print "Sending to ", wonder_couple.gifter_email
to_email = wonder_couple.gifter_email
msg_text = """
Sois o casal %s
Ides ofertar presentes ao casal %s
'mai nada!
""" % (wonder_couple.gifter_email, wonder_couple.gifted_email)
message = MIMEText(msg_text)
message['From'] = self.from_email
message['To'] = to_email
message['Subject'] = self.subject
server.sendmail(self.from_email, to_email, message.as_string())
server.quit()
print "All done!"
## couples settings
casais = []
## smtp server settings
smtp_server = 'smtp.gmail.com'
smtp_port = 587
from_email = ''
from_email_pwd = ""
subject = 'A roleta do jantar de Natal do sexta rodou e deciciu!!'
## run the thing
tacm = TheAwesomeCoupleMixer()
tacm.magicMixer(casais)
wonder_couples = tacm.getWonderCouples()
tfm = TheFabulousMailer(smtp_server, smtp_port, from_email, from_email_pwd, subject)
tfm.performLegendarySending(wonder_couples)