Move email notification to config file
This commit is contained in:
parent
b26802003d
commit
40a9e0f5f7
@ -9,8 +9,6 @@ import requests
|
||||
from microstacknode.hardware.accelerometer.mma8452q import MMA8452Q
|
||||
|
||||
|
||||
EMAIL_USERNAME = 'noreply@ianonavy.com'
|
||||
EMAIL_PASSWORD = 'S2PENjQbO6=cHgchw@CXs.bJ'
|
||||
RECIPIENT_EMAILS = ['ianonavy@gmail.com']
|
||||
ALERT_EMAIL_TEXT = """Hi,
|
||||
|
||||
@ -40,7 +38,7 @@ def stdev(s):
|
||||
return math.sqrt(average(list(variance)))
|
||||
|
||||
|
||||
def notify_user(recipient_email_address):
|
||||
def notify_user(username, password, recipient_email_address):
|
||||
log("Alerting " + recipient_email_address)
|
||||
|
||||
msg = MIMEText(ALERT_EMAIL_TEXT)
|
||||
@ -52,8 +50,6 @@ def notify_user(recipient_email_address):
|
||||
msg['To'] = recipient_email_address
|
||||
|
||||
# Send the message via our own SMTP server.
|
||||
username = EMAIL_USERNAME
|
||||
password = EMAIL_PASSWORD
|
||||
server = smtplib.SMTP('smtp.gmail.com:587')
|
||||
server.starttls()
|
||||
server.login(username, password)
|
||||
@ -95,7 +91,10 @@ def main():
|
||||
log('started laundry notifier')
|
||||
config = configparser.ConfigParser()
|
||||
config.read(CONFIG_FILE_PATH)
|
||||
iftttkey = config['notifications']['ifttt_key']
|
||||
notifications_section = config['notifications']
|
||||
iftttkey = notifications_section['ifttt_key']
|
||||
email_username = notifications_section['email_username']
|
||||
email_password = notifications_section['email_password']
|
||||
with MMA8452Q() as accelerometer:
|
||||
# Configure accelerometer
|
||||
accelerometer.standby()
|
||||
@ -120,6 +119,8 @@ def main():
|
||||
log('Dryer turned off; sliding stdev is %f' % sliding_stdev['x'])
|
||||
last_notification_sent_at = send_notifications(
|
||||
last_notification_sent_at,
|
||||
email_username,
|
||||
email_password,
|
||||
iftttkey)
|
||||
dryer_state = 'off'
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user