Skip to content

Commit

Permalink
New Features
Browse files Browse the repository at this point in the history
Can now set a friendly name for the FROM line of emails
New config option to delete old images at start of script
More message config options
  • Loading branch information
jakewaldron committed Mar 9, 2015
1 parent 76cf829 commit 21befb7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This script aggregates all new TV and movie releases for the past x days and wri

1. Python 2.7 - 32 bit - https://www.python.org/ftp/python/2.7.9/python-2.7.9.msi
2. 32 bit DLL for SQLite version 3.8.8.3 - http://www.sqlite.org/2015/sqlite-dll-win32-x86-3080803.zip (Put this into the DLLs folder of the Python installation)
3. If web reports are wanted, a web server (i.e. Wamp)
3. If web reports are wanted, a web server (i.e. Wamp, Apache, etc.)


## Installation (Windows)
Expand Down Expand Up @@ -99,12 +99,14 @@ The config file is in the scripts folder. Before first run of the script, pleas
* web_enabled - Enable the creation of the web page
* web_domain - Domain name of the web page
* web_path - Path on the domain to the web page
* web_delete_previous_images - True to delete all .jpg images in the web image folder prior to copying over current images

#####Email
* email_enabled - Enable the creation and sending of an email
* email_individually - True to send out emails individually to each address in the email_to setting
* email_to - Array of email addresses to send the email
* email_from - Email address to send the email from
* email_from_name - Friendly name of sender
* email_smtp_address - SMTP address of the email service
* email_smtp_port - SMTP port of the email service
* email_username - SMTP authentication username
Expand All @@ -118,6 +120,16 @@ The config file is in the scripts folder. Before first run of the script, pleas
* msg_header1 - First header text
* msg_header2 - Second header text
* msg_header3 - Third header text. Only used in the email
* msg_top_link - Header link text to go to top of the page
* msg_movies_link - Header link text to go to new movies
* msg_shows_link - Header link text to go to new shows
* msg_seasons_link - Header link text to go to new seasons
* msg_episodes_link - Header link text to go to new episodes
* msg_new_movies_header - Section header text for new movies
* msg_new_shows_header - Section header text for new shows
* msg_new_seasons_header - Section header text for new seasons
* msg_new_episodes_header - Section header text for new episodes
* msg_footer - Footer text at the bottom of the page

#####Sorting
* movie_sort_1 - Highest priority sort
Expand Down Expand Up @@ -147,6 +159,7 @@ The config file is in the scripts folder. Before first run of the script, pleas
* episode_sort_2_reverse - Reverse the default sort
* episode_sort_3 - Third Priority sort
* episode_sort_3_reverse - Reverse the default sort

## Screenshots

### Email
Expand Down
12 changes: 12 additions & 0 deletions scripts/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ days_back_to_search = 7
web_enabled = True
web_domain = ''
web_path = 'plexemail'
web_delete_previous_images = False

##Email
email_enabled = True
email_individually = False
# ['[email protected]', '[email protected]']
email_to = ['']
email_from = ''
email_from_name = 'Plex Server'
email_smtp_address = 'smtp.gmail.com'
email_smtp_port = 587
email_username = ''
Expand All @@ -35,6 +37,16 @@ msg_email_subject = 'New Plex Releases - {past_day} - {current_day}'
msg_header1 = 'New Plex Releases'
msg_header2 = '{past_day} - {current_day}'
msg_header3 = '<a href="{website}" style="color: #9A9A9A !important;">View as Website</a>'
msg_top_link = 'What\'s New in Plex'
msg_movies_link = 'Movies'
msg_shows_link = 'TV Shows'
msg_seasons_link = 'TV Seasons'
msg_episodes_link = 'TV Episodes'
msg_new_movies_header = 'New Movies'
msg_new_shows_header = 'New TV Shows'
msg_new_seasons_header = 'New TV Seasons'
msg_new_episodes_header = 'New TV Episodes'
msg_footer = ''

##Sorting
# Possible values = id, title, title_sort, original_title, rating, tagline,
Expand Down
48 changes: 27 additions & 21 deletions scripts/plexEmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.MIMEImage import MIMEImage
from email.header import Header
from email.utils import formataddr

def replaceConfigTokens():
for value in config:
Expand Down Expand Up @@ -72,6 +74,13 @@ def replaceConfigTokens():
config['episode_sort_2_reverse'] = False
if ('episode_sort_3_reverse' not in config.keys() or config['episode_sort_3_reverse'] == ""):
config['episode_sort_3_reverse'] = False

def deleteImages():
folder = config['web_folder'] + config['web_path'] + os.path.sep + 'images' + os.path.sep
for file in os.listdir(folder):
print folder, file
if (file.endswith('.jpg')):
os.remove(folder + file)

def processImage(imageHash, thumb, mediaType, seasonIndex, episodeIndex):
thumbObj = {}
Expand Down Expand Up @@ -133,11 +142,8 @@ def sendMail(email):
gmail_pwd = config['email_password']
smtp_address = config['email_smtp_address']
smtp_port = config['email_smtp_port']
FROM = config['email_from']
if (email != ''):
TO = email
else:
TO = config['email_to']
FROM = formataddr((str(Header(config['email_from_name'])), config['email_from'])) if ('email_from_name' in config) else config['email_from']
TO = email if (email != '') else config['email_to']
SUBJECT = config['msg_email_subject']

# Create message container - the correct MIME type is multipart/alternative.
Expand Down Expand Up @@ -173,7 +179,6 @@ def sendMail(email):
msg.attach(plaintext)
msg.attach(htmltext)
msg['To'] = ", ".join(TO)
print msg['To']
server = smtplib.SMTP(smtp_address, smtp_port) #or port 465 doesn't seem to work!
server.ehlo()
server.starttls()
Expand Down Expand Up @@ -297,22 +302,22 @@ def sendMail(email):
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">What's New in Plex</a>
<a class="navbar-brand" href="#">""" + config['msg_top_link'] + """</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a href="#movies-top">Movies</a>
<a href="#movies-top">""" + config['msg_movies_link'] + """</a>
</li>
<li>
<a href="#shows-top">TV Shows</a>
<a href="#shows-top">""" + config['msg_shows_link'] + """</a>
</li>
<li>
<a href="#seasons-top">TV Seasons</a>
<a href="#seasons-top">""" + config['msg_seasons_link'] + """</a>
</li>
<li>
<a href="#episodes-top">TV Episodes</a>
<a href="#episodes-top">""" + config['msg_episodes_link'] + """</a>
</li>
</ul>
</div>
Expand All @@ -335,38 +340,40 @@ def sendMail(email):
<div class="container">"""

emailMovies = """<div class="headline" style="background: #FFF !important; padding-top: 0px !important;">
<h1 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">New Movies</h1>
<h1 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">""" + config['msg_new_movies_header'] + """</h1>
</div><hr class="featurette-divider" id="movies-top"><br/>&nbsp;"""
htmlMovies = """<hr class="featurette-divider" id="movies-top">
<div class="headline" style="background: #FFF !important; padding-top: 0px !important;">
<h2 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">New Movies</h2>
<h2 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">""" + config['msg_new_movies_header'] + """</h2>
</div>"""
emailTVShows = """<div class="headline" style="background: #FFF !important; padding-top: 0px !important;">
<h1 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">New TV Shows</h1>
<h1 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">""" + config['msg_new_shows_header'] + """</h1>
</div><hr class="featurette-divider" id="movies-top"><br/>&nbsp;"""
htmlTVShows = """<hr class="featurette-divider" id="shows-top">
<div class="headline" style="background: #FFF !important; padding-top: 0px !important;">
<h2 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">New TV Shows</h2>
<h2 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">""" + config['msg_new_shows_header'] + """</h2>
</div>"""
emailTVSeasons = """<div class="headline" style="background: #FFF !important; padding-top: 0px !important;">
<h1 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">New TV Seasons</h1>
<h1 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">""" + config['msg_new_seasons_header'] + """</h1>
</div><hr class="featurette-divider" id="movies-top"><br/>&nbsp;"""
htmlTVSeasons = """<hr class="featurette-divider" id="seasons-top">
<div class="headline" style="background: #FFF !important; padding-top: 0px !important;">
<h2 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">New TV Seasons</h2>
<h2 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">""" + config['msg_new_seasons_header'] + """</h2>
</div>"""
emailTVEpisodes = """<div class="headline" style="background: #FFF !important; padding-top: 0px !important;">
<h1 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">New TV Episodes</h1>
<h1 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">""" + config['msg_new_episodes_header'] + """</h1>
</div><hr class="featurette-divider" id="movies-top"><br/>&nbsp;"""
htmlTVEpisodes = """<hr class="featurette-divider" id="episodes-top">
<div class="headline" style="background: #FFF !important; padding-top: 0px !important;">
<h2 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">New TV Episodes</h2>
<h2 style="width: 100%; text-align: center; background: #FFF !important; color: #F9AA03 !important;">""" + config['msg_new_episodes_header'] + """</h2>
</div>"""
movies = {}
tvShows = {}
tvSeasons = {}
tvEpisodes = {}
imgNames = {}
if (config['web_enabled'] and 'web_delete_previous_images' in config and config['web_delete_previous_images']):
deleteImages()
for item in response:
#Handle New Movies
if (response[item]['metadata_type'] == 1):
Expand Down Expand Up @@ -633,7 +640,7 @@ def sendMail(email):
<footer>
<div class="row">
<div class="col-lg-12">
<p>Copyright &copy; Jake Waldron 2015</p>
<p>""" + config['msg_footer'] + """</p>
</div>
</div>
</footer>
Expand Down Expand Up @@ -661,7 +668,6 @@ def sendMail(email):
if (config['email_individually']):
for emailAdd in config['email_to']:
email = [emailAdd]
print email
sendMail(email)
emailCount += 1
else:
Expand Down

0 comments on commit 21befb7

Please sign in to comment.