Added email messaging
This commit is contained in:
5
EmailSettings.cfg
Normal file
5
EmailSettings.cfg
Normal file
@@ -0,0 +1,5 @@
|
||||
SMTPServer = ""
|
||||
SMTPUser = ""
|
||||
SMTPPassword = ""
|
||||
From = ""
|
||||
To = ""
|
||||
24
TVEncoder.py
24
TVEncoder.py
@@ -10,11 +10,14 @@ import getopt
|
||||
from libfilemanager import FileManager
|
||||
from libsettings import Settings
|
||||
import libhandbrake
|
||||
import libemail
|
||||
from libtvdatasource import TVData
|
||||
from collections import namedtuple
|
||||
from termcolor import colored
|
||||
import logging
|
||||
|
||||
SETTINGS = "settings.cfg"
|
||||
EMAIL_SETTINGS = "EmailSettings.cfg"
|
||||
|
||||
def showhelp():
|
||||
"""
|
||||
@@ -101,15 +104,9 @@ def main(argv):
|
||||
sys.exit(2)
|
||||
inputoptions = processarguments(opts)
|
||||
|
||||
settings = Settings("settings.cfg")
|
||||
settings = Settings(SETTINGS)
|
||||
filemanager = FileManager(settings)
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
generallogger = createlogger("general", settings.generallogfile(),
|
||||
logging.DEBUG)
|
||||
actionlogger = createlogger("action", settings.actionlogfile(),
|
||||
logging.INFO)
|
||||
|
||||
if inputoptions.readonly:
|
||||
if inputoptions.doencode:
|
||||
#Generate the list of files that would be encoded
|
||||
@@ -123,6 +120,13 @@ def main(argv):
|
||||
else:
|
||||
if inputoptions.doencode:
|
||||
#Encode the files and move them to their final destination
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
generallogger = createlogger("general", settings.generallogfile(),
|
||||
logging.DEBUG)
|
||||
actionlogger = createlogger("action", settings.actionlogfile(),
|
||||
logging.INFO)
|
||||
|
||||
showdata = filemanager.getencodingfiles(inputoptions.readonly)
|
||||
generallogger.info("There are {0} files to process."
|
||||
.format(len(showdata)))
|
||||
@@ -149,6 +153,10 @@ def main(argv):
|
||||
generallogger.info("Processing finished.")
|
||||
generallogger.info("==========================="
|
||||
"=============\n\n")
|
||||
|
||||
libemail.SendEmail(EMAIL_SETTINGS, "Encoding Complete",
|
||||
"Finished encoding {0} shows."
|
||||
.format(len(showdata)))
|
||||
else:
|
||||
# Process files for encoding
|
||||
shows = filemanager.getfilestoprepare(inputoptions.numfiles)
|
||||
@@ -163,7 +171,7 @@ def createlogger(name, filename, level):
|
||||
"""
|
||||
|
||||
logger = logging.getLogger(name)
|
||||
handler = logging.FileHandler(filename)
|
||||
handler = logging.FileHandler(filename, mode='w')
|
||||
formatter = logging.Formatter('%(asctime)s %(message)s')
|
||||
handler.setFormatter(formatter)
|
||||
handler.setLevel(level)
|
||||
|
||||
28
libemail.py
Normal file
28
libemail.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Sat Jul 20 20:48:10 2013
|
||||
|
||||
@author: shanef
|
||||
"""
|
||||
|
||||
from libsettings import EmailSettings
|
||||
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
|
||||
def SendEmail(settingsfilename, subject, body):
|
||||
settings = EmailSettings(settingsfilename)
|
||||
|
||||
msg = MIMEText(body, "plain")
|
||||
msg["Subject"] = subject
|
||||
msg["From"] = settings.getfromaddress()
|
||||
msg["To"] = settings.gettoaddress()
|
||||
|
||||
s = smtplib.SMTP(settings.getsmtpserver())
|
||||
s.ehlo()
|
||||
s.starttls()
|
||||
s.login(settings.getsmtpuser(), settings.getsmtppassword())
|
||||
s.sendmail(settings.getfromaddress(), [settings.gettoaddress()],
|
||||
msg.as_string())
|
||||
s.quit()
|
||||
@@ -231,7 +231,7 @@ class Settings:
|
||||
# just returns what is input
|
||||
def getshow(self, showname):
|
||||
"""
|
||||
Get the InputDirectory setting for the show, showname.
|
||||
Get the name of the show, showname.
|
||||
"""
|
||||
showsection = self.__getshowsubsection(showname)
|
||||
if showsection is None:
|
||||
@@ -252,3 +252,51 @@ class Settings:
|
||||
return self.__config["Shows"][show]
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class EmailSettings:
|
||||
"""
|
||||
Accessor for the email configuration file
|
||||
"""
|
||||
|
||||
def __init__(self, settingsfile):
|
||||
"""
|
||||
Initialise settingsfile as a configobj
|
||||
"""
|
||||
|
||||
self.__config = ConfigObj(settingsfile)
|
||||
|
||||
def getsmtpserver(self):
|
||||
"""
|
||||
Get the address of the smtp server
|
||||
"""
|
||||
|
||||
return self.__config["SMTPServer"]
|
||||
|
||||
def getsmtpuser(self):
|
||||
"""
|
||||
Get the username for the smtp server
|
||||
"""
|
||||
|
||||
return self.__config["SMTPUser"]
|
||||
|
||||
def getsmtppassword(self):
|
||||
"""
|
||||
Get the username for the smtp server
|
||||
"""
|
||||
|
||||
return self.__config["SMTPPassword"]
|
||||
|
||||
def getfromaddress(self):
|
||||
"""
|
||||
Get the from address for emails
|
||||
"""
|
||||
|
||||
return self.__config["From"]
|
||||
|
||||
def gettoaddress(self):
|
||||
"""
|
||||
Get the to address for emails
|
||||
"""
|
||||
|
||||
return self.__config["To"]
|
||||
0
logs/encoding.log
Normal file
0
logs/encoding.log
Normal file
0
logs/needsaction.log
Normal file
0
logs/needsaction.log
Normal file
7
tests/emailtest.py
Normal file
7
tests/emailtest.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Fri Jul 19 23:31:16 2013
|
||||
|
||||
@author: shanef
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user