From 4664574f7f78a3f8197212be4aba8bc8f9af8286 Mon Sep 17 00:00:00 2001 From: jakewaldron Date: Thu, 12 Mar 2015 21:09:15 -0700 Subject: [PATCH] Added Command Line Usage and Parameters Added the option to pass in an alternative config file. --- README.md | 16 ++++++++++++++++ scripts/plexEmail.py | 22 ++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 63d273f..d3573c3 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,22 @@ sudo virtualenv --python=/usr/local/bin/python2.7 pevenv ~/plexemail/scripts/pevenv/bin/python ~/plexemail/scripts/plexEmail.py ``` +## Usage + +#### Normal Usage + +``` +python plexEmail.py +``` + +#### Alternate Usage + +Pass in an alternate config file. For example the default config file sends out a daily email (using Cloudinary), while an alternate config file is set up for a weekly web page. + +``` +python plexEmail.py -c C:\files\plexEmailWeekly.conf +``` + ## Config File The config file is in the scripts folder. Before first run of the script, please update this file with your information. diff --git a/scripts/plexEmail.py b/scripts/plexEmail.py index 263bf51..421bdba 100644 --- a/scripts/plexEmail.py +++ b/scripts/plexEmail.py @@ -1,5 +1,6 @@ import sqlite3 import sys +import argparse import os import json import operator @@ -465,9 +466,26 @@ def createWebHTML(): """ return htmlText - + +# +# +# Main Code +# +# + +parser = argparse.ArgumentParser(description='This script aggregates all new TV and movie releases for the past x days then writes to your web directory and sends out an email.') +parser.add_argument('-c','--configfile', help='The path to a config file to be used in the running of this instance of the script.', default=os.path.dirname(os.path.realpath(sys.argv[0])) + os.path.sep + 'config.conf', required=False) +args = vars(parser.parse_args()) + +if ('configfile' in args): + configFile = args['configfile'] + +if (not os.path.isfile(configFile)): + print configFile + ' does not exist' + sys.exit() + config = {} -execfile(os.path.dirname(os.path.realpath(sys.argv[0])) + os.path.sep + 'config.conf', config) +execfile(configFile, config) replaceConfigTokens() if ('upload_use_cloudinary' in config and config['upload_use_cloudinary']):