-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers.py
More file actions
executable file
·47 lines (38 loc) · 1.33 KB
/
helpers.py
File metadata and controls
executable file
·47 lines (38 loc) · 1.33 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
from builtins import str
import config as cfg
from flask_login import current_user
from datetime import datetime, timedelta
import smtplib
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
def email_msg(txt, subj, recipient, header=True, render_html=False):
gmail_pw = cfg.GRDO_GMAIL_PW
if header:
cur_user = str(current_user.get_id()) if current_user else 'anonymous'
deets = datetime.now().strftime('%Y-%m-%d %H:%M:%S') +\
'; userID=' + cur_user + '\n'
txt = deets + txt
#compose email
msg = MIMEMultipart()
if render_html:
msg.attach(MIMEText(txt, 'html'))
else:
msg.attach(MIMEText(txt))
msg['Subject'] = subj
msg['From'] = 'grdouser@gmail.com'
msg['To'] = recipient
#log in to gmail, send email
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login("grdouser@gmail.com", gmail_pw)
server.sendmail('grdouser@gmail.com', [recipient],
msg.as_string())
server.quit()
# Get 2 week plot intervals
def get_twoweek_windows(start, end):
r = (end + timedelta(days=1) - start).days
if r % 14 >= 0:
r = r + 14
return [(end - timedelta(days=i)).strftime('%Y-%m-%d') for i in range(0, r, 14)]