-
Notifications
You must be signed in to change notification settings - Fork 0
/
raven.py
80 lines (69 loc) · 1.73 KB
/
raven.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
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
"""This modules sends summary emails.
"""
from __future__ import print_function
import os
import time
import datetime
import smtplib
from getpass import getpass
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from report import report
from lawyer import rules
TEXT = """
Current Cone Cache
------------------
Ley line of credit for each player:
{report}
Rules
-----
{rules}
"""
HTML = """
<html>
<head></head>
<body>
<h2>Current Cone Cache</h2>
Ley line of credit for each player:<br/><br/>
{report}
<hr/>
<h2>Rules</h2>
{rules}
</body>
</html>
"""
def passwd(user):
fname = '{0}.pw'.format(user.split('@', 1)[0])
if not os.path.isfile(fname):
pw = getpass('password for {0}:'.format(user))
with open(fname, 'w') as f:
f.write(pw)
with open(fname, 'r') as f:
pw = f.read()
return pw
def send(trans):
"""Sends an email to the list."""
me = '[email protected]'
you = '[email protected]'
today = datetime.date.today()
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = 'Magic Cones Report {0}'.format(today)
msg['From'] = me
msg['To'] = you
# create content
text = TEXT.format(report=report(trans), rules=rules())
html = HTML.format(report=report(trans, html=True), rules=rules(html=True))
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
# Send the message
pw = passwd(me)
s = smtplib.SMTP('smtp.gmail.com', 587)
#s.ehlo()
s.starttls()
#s.ehlo()
s.login(me, pw)
s.sendmail(me, you, msg.as_string())
s.quit()