-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first go at using fabric to send the email
- Loading branch information
1 parent
ad39bbf
commit 48cadcf
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from fabric.api import task | ||
|
||
import smtplib | ||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.text import MIMEText | ||
|
||
import datetime | ||
import os | ||
|
||
import commands | ||
|
||
username = os.environ['SENDGRID_USERNAME'] | ||
password = os.environ['SENDGRID_PASSWORD'] | ||
to_email = os.environ['CRON_EMAIL'] | ||
|
||
def send_email(email_msg): | ||
print "Running cron at %s" % datetime.datetime.now() | ||
|
||
msg = MIMEMultipart('alternative') | ||
msg['Subject'] = "Comcast Bandwidth Usage" | ||
msg['From'] = username | ||
msg['To'] = to_email | ||
msg.attach(MIMEText(email_msg, 'plain')) | ||
|
||
s = smtplib.SMTP('smtp.sendgrid.net', 587) | ||
s.login(username, password) | ||
s.sendmail(username, to_email, msg.as_string()) | ||
s.quit() | ||
|
||
@task | ||
def send(): | ||
output = commands.getoutput('python comcastBandwidth.py') | ||
send_email(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mechanize | ||
fabric |