Commit 586994de authored by Anastasia Galkin's avatar Anastasia Galkin
Browse files

email fixed, format fixed

parent 1c1e3be0
......@@ -4,6 +4,7 @@ import time
import MySQLdb
import logging
import smtplib
import email.message
import socket
from settings import *
......@@ -16,7 +17,7 @@ hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
# email
# email payload
msg_body = EMAIL_CONF['FROM'] + ':\n'
# Open database connection
......@@ -48,12 +49,11 @@ for instance, wp in WORDPRESS_DATABASES.items():
nonews = False
news = news + "{1}: {0}\n".format(''.join(map(str, count)), queries)
logger.info(db_name + " - {1}: {0}".format(''.join(map(str, count)), queries))
cursor.execute(stats['query'])
for row in cursor:
news = news + ' '.join(map(str, row)) + '\n'
logger.info(db_name + ' ,'.join(map(str, row)))
news = news + ', '.join(map(str, row)) + '\n'
logger.info(db_name + queries + ' ' + ' '.join(map(str, row)))
db.close()
......@@ -66,9 +66,17 @@ for instance, wp in WORDPRESS_DATABASES.items():
msg_body = msg_body + news
# email
msg = email.message.Message()
msg['Subject'] = EMAIL_CONF['SUBJECT']
msg['From'] = EMAIL_CONF['FROM']
msg['To'] = ' ,'.join(EMAIL_CONF['TO'])
msg.add_header('Content-Type','text')
msg.set_payload(msg_body)
try:
server = smtplib.SMTP(EMAIL_CONF['SMTP_SERVER'], EMAIL_CONF['PORT'])
server.sendmail(EMAIL_CONF['FROM'],EMAIL_CONF['TO'], msg_body)
server.sendmail(EMAIL_CONF['FROM'], EMAIL_CONF['TO'], msg.as_string())
server.close()
except (smtplib.SMTPException, KeyError, TypeError, socket.error) as err:
logger.error('SMTP server: ' + err.__str__())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment