-
Notifications
You must be signed in to change notification settings - Fork 1
/
output.py
50 lines (41 loc) · 1.75 KB
/
output.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from abc import ABCMeta, abstractmethod
from email.mime.text import MIMEText
from email.header import Header
from string import Template
import smtplib
class Output:
__metaclass__ = ABCMeta
@abstractmethod
def process(self, playerPairs):
pass
class Debug(Output):
def process(self, playerPairs):
for gifter,receiver in playerPairs:
print gifter.tostring() + " --> " + receiver.tostring()
class SMTP(Output):
def __init__(self, email_address, password):
self.email_address = email_address
self.password = password
def process(self, playerPairs):
subject = "🎵It's beginning to feel a lot like Christmas!🎵"
body_template = Template("Hey $gfname, it's that time of year again!<br><br>"
+ "You are <b>$rname</b>'s Secret Santa! If you're lucky, $rfname might have put some wishes on the <a href=\"https://goo.gl/Ue1wYf\">Christmas Wishlist</a>. And even if they didn't, consider helping them out by giving them some hints!<br><br>"
+ "Good luck, and Happy Holidays! 🎄<br>"
+ "- Secret Santa Bot")
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(self.email_address, self.password)
for gifter,receiver in playerPairs:
if ((gifter.getemail() == None) or (gifter.getemail() == "None")):
print("WARN: No email listed for " + gifter.getname())
continue
body = body_template.substitute(gfname=gifter.getfirstname(), rfname=receiver.getfirstname(), rname=receiver.getname())
send_this = MIMEText(body, 'html', 'utf-8')
send_this['Subject'] = Header(subject, 'utf-8')
send_this['From'] = self.email_address
send_this['To'] = gifter.getemail()
server.sendmail(self.email_address, gifter.getemail(), send_this.as_string())
server.quit()