From 85772cdd83adbe63124f8373442bcaaa16b92fb7 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Fri, 11 May 2018 19:18:05 -0700 Subject: [PATCH] Strip whitespace before sending newsletters --- .../newsletters/recently_added.html | 748 ++++++++--------- .../newsletters/recently_added.inline.html | 750 ++++++++---------- plexpy/newsletters.py | 7 +- 3 files changed, 636 insertions(+), 869 deletions(-) diff --git a/data/interfaces/newsletters/recently_added.html b/data/interfaces/newsletters/recently_added.html index 135c7088..58d67db9 100644 --- a/data/interfaces/newsletters/recently_added.html +++ b/data/interfaces/newsletters/recently_added.html @@ -68,17 +68,14 @@ width: 100%; } - /* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */ .container { display: block; margin: 0 auto !important; - /* makes it centered */ max-width: 1042px; padding: 10px; width: 1042px; } - /* This should also be a block element, so that it will fill 100% of the .container */ .content { box-sizing: border-box; display: block; @@ -172,88 +169,9 @@ text-decoration: underline; } - /* ------------------------------------- - BUTTONS - ------------------------------------- */ - .btn { - box-sizing: border-box; - width: 100%; - } - - .btn > tbody > tr > td { - padding-bottom: 15px; - } - - .btn table { - width: auto; - } - - .btn table td { - background-color: #ffffff; - border-radius: 5px; - text-align: center; - } - - .btn a { - background-color: #ffffff; - border: solid 1px #3498db; - border-radius: 5px; - box-sizing: border-box; - color: #3498db; - cursor: pointer; - display: inline-block; - font-size: 14px; - font-weight: bold; - margin: 0; - padding: 12px 25px; - text-decoration: none; - text-transform: capitalize; - } - - .btn-primary table td { - background-color: #3498db; - } - - .btn-primary a { - background-color: #3498db; - border-color: #3498db; - color: #ffffff; - } - /* ------------------------------------- OTHER STYLES THAT MIGHT BE USEFUL ------------------------------------- */ - .last { - margin-bottom: 0; - } - - .first { - margin-top: 0; - } - - .align-center { - text-align: center; - } - - .align-right { - text-align: right; - } - - .align-left { - text-align: left; - } - - .clear { - clear: both; - } - - .mt0 { - margin-top: 0; - } - - .mb0 { - margin-bottom: 0; - } .mb5 { margin-bottom: 5px; } @@ -263,9 +181,6 @@ text-overflow: ellipsis; overflow: hidden; } - .clear { - clear: both; - } .preheader { color: transparent; @@ -324,6 +239,7 @@ margin-left: auto; margin-right: auto; } + /* ------------------------------------- MEDIA SECTIONS ------------------------------------- */ @@ -378,6 +294,7 @@ font-size: 20px; text-transform: uppercase; } + /* ------------------------------------- MEDIA CARDS ------------------------------------- */ @@ -480,21 +397,21 @@ padding-left: 5px; } .card-info-footer .badge-container { - max-width: 265px; + max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .card-info-footer .star-rating-container { - width: 60px; - vertical-align: bottom; - padding-right: 5px; + width: 65px; } .card-info-footer .star-rating { + margin-left: 4px; font-size: 0.8rem; line-height: 1rem; width: 0.5rem; display: inline-block; + vertical-align: bottom; } .star-rating.full { color: #E5A00D; @@ -505,6 +422,7 @@ .badge { display: inline-block; min-width: 10px; + margin-right: 4px; padding: 3px 7px; font-size: 11px; line-height: 1; @@ -609,20 +527,11 @@ line-height: inherit !important; text-decoration: none !important; } - - .btn-primary table td:hover { - background-color: #34495e !important; - } - - .btn-primary a:hover { - background-color: #34495e !important; - border-color: #34495e !important; - } } - + % if preview and service and service != 'self-hosted':

Note: Local preview images only - images will be uploaded to ${service.capitalize()} when the newsletter is sent.

% elif preview and not service: @@ -632,19 +541,13 @@
- - Tautulli Newsletter - ${subject} - % if base_url and not preview: % endif - - - - % if message: % endif - % if recently_added.get('movie'):
@@ -654,7 +557,6 @@
${parameters['start_date']} - ${parameters['end_date']}
@@ -663,7 +565,6 @@
@@ -679,109 +580,105 @@
- - % for movie_a, movie_b in grouper(recently_added['movie'], 2): - - @@ -803,142 +700,137 @@
- - - - % for movie in (movie_a, movie_b): - % if movie: - % if not movie_b: - - % endif - + + % endfor
- - + % for movie_a, movie_b in grouper(recently_added['movie'], 2): + + + % if not movie_b: + + % endif + % endif + % endfor + +
+ + + % for movie in (movie_a, movie_b): + % if movie: + % if not movie_b: + + % endif + + +
+ + + - - % endfor - +
+ - - + - % if not movie_b: - - % endif - % endif - % endfor - - -
- - - - - - -
- - - -
+
+ + + - - - - - - - - - - - - + +
- ${movie['title']} -
- % if movie['tagline']: -

- ${movie['tagline']} -

- % endif -

- ${movie['summary'][:450] + (movie['summary'][450:] and '...')} -

-
+
+ + + + + + + + + - -
+ ${movie['title']} +
+ % if movie['tagline']: +

+ ${movie['tagline']} +

+ % endif +

+ ${movie['summary'][:450] + (movie['summary'][450:] and '...')} +

+
-
-
+
+
+
- - % for show_a, show_b in grouper(recently_added['show'], 2): - - @@ -960,124 +852,114 @@ diff --git a/data/interfaces/newsletters/recently_added.inline.html b/data/interfaces/newsletters/recently_added.inline.html index 06d3d000..4c5991d4 100644 --- a/data/interfaces/newsletters/recently_added.inline.html +++ b/data/interfaces/newsletters/recently_added.inline.html @@ -68,17 +68,14 @@ width: 100%; } - /* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */ .container { display: block; margin: 0 auto !important; - /* makes it centered */ max-width: 1042px; padding: 10px; width: 1042px; } - /* This should also be a block element, so that it will fill 100% of the .container */ .content { box-sizing: border-box; display: block; @@ -172,88 +169,9 @@ text-decoration: underline; } - /* ------------------------------------- - BUTTONS - ------------------------------------- */ - .btn { - box-sizing: border-box; - width: 100%; - } - - .btn > tbody > tr > td { - padding-bottom: 15px; - } - - .btn table { - width: auto; - } - - .btn table td { - background-color: #ffffff; - border-radius: 5px; - text-align: center; - } - - .btn a { - background-color: #ffffff; - border: solid 1px #3498db; - border-radius: 5px; - box-sizing: border-box; - color: #3498db; - cursor: pointer; - display: inline-block; - font-size: 14px; - font-weight: bold; - margin: 0; - padding: 12px 25px; - text-decoration: none; - text-transform: capitalize; - } - - .btn-primary table td { - background-color: #3498db; - } - - .btn-primary a { - background-color: #3498db; - border-color: #3498db; - color: #ffffff; - } - /* ------------------------------------- OTHER STYLES THAT MIGHT BE USEFUL ------------------------------------- */ - .last { - margin-bottom: 0; - } - - .first { - margin-top: 0; - } - - .align-center { - text-align: center; - } - - .align-right { - text-align: right; - } - - .align-left { - text-align: left; - } - - .clear { - clear: both; - } - - .mt0 { - margin-top: 0; - } - - .mb0 { - margin-bottom: 0; - } .mb5 { margin-bottom: 5px; } @@ -263,9 +181,6 @@ text-overflow: ellipsis; overflow: hidden; } - .clear { - clear: both; - } .preheader { color: transparent; @@ -324,6 +239,7 @@ margin-left: auto; margin-right: auto; } + /* ------------------------------------- MEDIA SECTIONS ------------------------------------- */ @@ -378,6 +294,7 @@ font-size: 20px; text-transform: uppercase; } + /* ------------------------------------- MEDIA CARDS ------------------------------------- */ @@ -480,21 +397,21 @@ padding-left: 5px; } .card-info-footer .badge-container { - max-width: 265px; + max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .card-info-footer .star-rating-container { - width: 60px; - vertical-align: bottom; - padding-right: 5px; + width: 65px; } .card-info-footer .star-rating { + margin-left: 4px; font-size: 0.8rem; line-height: 1rem; width: 0.5rem; display: inline-block; + vertical-align: bottom; } .star-rating.full { color: #E5A00D; @@ -505,6 +422,7 @@ .badge { display: inline-block; min-width: 10px; + margin-right: 4px; padding: 3px 7px; font-size: 11px; line-height: 1; @@ -609,21 +527,12 @@ line-height: inherit !important; text-decoration: none !important; } - - .btn-primary table td:hover { - background-color: #34495e !important; - } - - .btn-primary a:hover { - background-color: #34495e !important; - border-color: #34495e !important; - } } - -% if preview and service and service != 'self-hosted' : + +% if preview and service and service != 'self-hosted':

Note: Local preview images only - images will be uploaded to ${service.capitalize()} when the newsletter is sent.

% elif preview and not service:

Warning: The Image Hosting setting must be enabled for images to display on the newsletter.

@@ -632,19 +541,13 @@
- - - - % for show in (show_a, show_b): - % if show: - % if not show_b: - - % endif - <% - if show['season_count'] == 1: - if show['season'][0]['episode_count'] == 1: - link_rating_key = show['season'][0]['episode'][0]['rating_key'] - else: - link_rating_key = show['season'][0]['episode'][0]['parent_rating_key'] - else: - link_rating_key = show['rating_key'] - %> - + + % endfor
- - + % for show_a, show_b in grouper(recently_added['show'], 2): + + + % if not show_b: + + % endif + % endif + % endfor + +
+ + + % for show in (show_a, show_b): + % if show: + % if not show_b: + + % endif + <% + if show['season_count'] == 1: + if show['season'][0]['episode_count'] == 1: + link_rating_key = show['season'][0]['episode'][0]['rating_key'] + else: + link_rating_key = show['season'][0]['episode'][0]['parent_rating_key'] + else: + link_rating_key = show['rating_key'] + %> + + +
+ + + - - % endfor - +
+ - - + - % if not show_b: - - % endif - % endif - % endfor - - -
- - - - - - -
- - - -
+
+ + + - - - - - - - +
- ${show['title']} -
-

- % if show['season_count'] > 1: - ${show['season_count']} seasons / +

+
+ + + + + + + + + - -
+ ${show['title']} +
+

+ % if show['season_count'] > 1: + ${show['season_count']} seasons / + % endif + <% total_show_episodes = sum(s['episode_count'] for s in show['season']) %> + ${total_show_episodes} episode${'s' if total_show_episodes > 1 else ''} +

+

+ % for i, season in enumerate(show['season'][:8]): + % if season['episode_count'] == 1: + Season ${season['media_index']} · Episode ${season['episode'][0]['media_index']} - ${season['episode'][0]['title']} + % else: + Season ${season['media_index']} · Episodes ${season['episode_range']} + % endif + % if i < min(show['season_count'], 7): +
+ % elif i == 7 and show['season_count'] > 8: + ...plus ${show['season_count'] - 8} more seasons! + % endif + % endfor +

+

+ % if show['season_count'] == 1 and show['season'][0]['episode_count'] == 1: + ${show['season'][0]['episode'][0]['summary'][:350] + (show['season'][0]['episode'][0]['summary'][350:] and '...')} + % else: + <% length = max(0, 350 - 50 * (show['season_count'] - 1)) %> + % if length: + ${show['summary'][:length] + (show['summary'][length:] and '...')} + % endif + % endif +

+
-
-
+
+
+
- - % for album_a, album_b in grouper([a for artist in recently_added['artist'] for a in artist['album']], 2): - - % endif - -
- - - - % for album in (album_a, album_b): - % if album: - % if not album_b: - - % endif - + + % endfor
- - + % for album_a, album_b in grouper([a for artist in recently_added['artist'] for a in artist['album']], 2): + + + % if not album_b: + + % endif + % endif + % endfor + +
+ + + % for album in (album_a, album_b): + % if album: + % if not album_b: + + % endif + + +
+ + + - - % endfor - +
+ - - + - % if not album_b: - - % endif - % endif - % endfor - - -
- - - - - - -
- - - -
+
+ + + - - - - - - - - - - - - + +
- ${album['title']} -
-

- ${album['parent_title']} · ${album['track_count']} track${'s' if album['track_count'] > 1 else ''} -

- % if artist['title'].lower() != 'various artists': -

- ${album['summary'][:200] + (album['summary'][200:] and '...')} -

- % endif -
+
+ + + + + + + + + - -
+ ${album['title']} +
+

+ ${album['parent_title']} · ${album['track_count']} track${'s' if album['track_count'] > 1 else ''} +

+ % if artist['title'].lower() != 'various artists': +

+ ${album['summary'][:200] + (album['summary'][200:] and '...')} +

+ % endif +
-
-
+
+
+
- -
- - - % if base_url and not preview: % endif - - - - % if message: % endif - % if recently_added.get('movie'):
@@ -654,7 +557,6 @@
${parameters['start_date']} - ${parameters['end_date']}
@@ -663,7 +565,6 @@
@@ -679,109 +580,105 @@
- - % for movie_a, movie_b in grouper(recently_added['movie'], 2): - - @@ -803,142 +700,137 @@
- - - - % for movie in (movie_a, movie_b): - % if movie: - % if not movie_b: - - % endif - + + % endfor
- - + % for movie_a, movie_b in grouper(recently_added['movie'], 2): + + + % if not movie_b: + + % endif + % endif + % endfor + +
+ + + % for movie in (movie_a, movie_b): + % if movie: + % if not movie_b: + + % endif + + +
+ + + - - % endfor - +
+ - - + - % if not movie_b: - - % endif - % endif - % endfor - - -
- - - - - - -
- - - -
+
+ + + - - - - - - - - - - - - + +
- ${movie['title']} -
- % if movie['tagline']: -

- ${movie['tagline']} -

- % endif -

- ${movie['summary'][:450] + (movie['summary'][450:] and '...')} -

-
+
+ + + + + + + + + - -
+ ${movie['title']} +
+ % if movie['tagline']: +

+ ${movie['tagline']} +

+ % endif +

+ ${movie['summary'][:450] + (movie['summary'][450:] and '...')} +

+
-
-
+
+
+
- - % for show_a, show_b in grouper(recently_added['show'], 2): - - @@ -960,124 +852,114 @@ diff --git a/plexpy/newsletters.py b/plexpy/newsletters.py index e93ae078..64c05558 100644 --- a/plexpy/newsletters.py +++ b/plexpy/newsletters.py @@ -456,6 +456,7 @@ class Newsletter(object): for line in self.newsletter.encode('utf-8').splitlines(): if '' not in line: n_file.write(line + '\r\n') + #n_file.write(line.strip()) logger.info(u"Tautulli Newsletters :: %s newsletter saved to '%s'" % (self.NAME, newsletter_file)) except OSError as e: @@ -464,18 +465,20 @@ class Newsletter(object): def _send(self): if self.config['formatted']: + newsletter_stripped = ''.join(l.strip() for l in self.newsletter.splitlines()) + if self.email_config['notifier_id']: return send_notification( notifier_id=self.email_config['notifier_id'], subject=self.subject_formatted, - body=self.newsletter + body=newsletter_stripped ) else: email = EMAIL(config=self.email_config) return email.notify( subject=self.subject_formatted, - body=self.newsletter + body=newsletter_stripped ) elif self.config['notifier_id']: return send_notification(
- - - - % for show in (show_a, show_b): - % if show: - % if not show_b: - - % endif - <% - if show['season_count'] == 1: - if show['season'][0]['episode_count'] == 1: - link_rating_key = show['season'][0]['episode'][0]['rating_key'] - else: - link_rating_key = show['season'][0]['episode'][0]['parent_rating_key'] - else: - link_rating_key = show['rating_key'] - %> - + + % endfor
- - + % for show_a, show_b in grouper(recently_added['show'], 2): + + + % if not show_b: + + % endif + % endif + % endfor + +
+ + + % for show in (show_a, show_b): + % if show: + % if not show_b: + + % endif + <% + if show['season_count'] == 1: + if show['season'][0]['episode_count'] == 1: + link_rating_key = show['season'][0]['episode'][0]['rating_key'] + else: + link_rating_key = show['season'][0]['episode'][0]['parent_rating_key'] + else: + link_rating_key = show['rating_key'] + %> + + +
+ + + - - % endfor - +
+ - - + - % if not show_b: - - % endif - % endif - % endfor - - -
- - - - - - -
- - - -
+
+ + + - - - - - - - +
- ${show['title']} -
-

- % if show['season_count'] > 1: - ${show['season_count']} seasons / +

+
+ + + + + + + + + - -
+ ${show['title']} +
+

+ % if show['season_count'] > 1: + ${show['season_count']} seasons / + % endif + <% total_show_episodes = sum(s['episode_count'] for s in show['season']) %> + ${total_show_episodes} episode${'s' if total_show_episodes > 1 else ''} +

+

+ % for i, season in enumerate(show['season'][:8]): + % if season['episode_count'] == 1: + Season ${season['media_index']} · Episode ${season['episode'][0]['media_index']} - ${season['episode'][0]['title']} + % else: + Season ${season['media_index']} · Episodes ${season['episode_range']} + % endif + % if i < min(show['season_count'], 7): +
+ % elif i == 7 and show['season_count'] > 8: + ...plus ${show['season_count'] - 8} more seasons! + % endif + % endfor +

+

+ % if show['season_count'] == 1 and show['season'][0]['episode_count'] == 1: + ${show['season'][0]['episode'][0]['summary'][:350] + (show['season'][0]['episode'][0]['summary'][350:] and '...')} + % else: + <% length = max(0, 350 - 50 * (show['season_count'] - 1)) %> + % if length: + ${show['summary'][:length] + (show['summary'][length:] and '...')} + % endif + % endif +

+
-
-
+
+
+
- - % for album_a, album_b in grouper([a for artist in recently_added['artist'] for a in artist['album']], 2): - - % endif - -
- - - - % for album in (album_a, album_b): - % if album: - % if not album_b: - - % endif - + + % endfor
- - + % for album_a, album_b in grouper([a for artist in recently_added['artist'] for a in artist['album']], 2): + + + % if not album_b: + + % endif + % endif + % endfor + +
+ + + % for album in (album_a, album_b): + % if album: + % if not album_b: + + % endif + + +
+ + + - - % endfor - +
+ - - + - % if not album_b: - - % endif - % endif - % endfor - - -
- - - - - - -
- - - -
+
+ + + - - - - - - - - - - - - + +
- ${album['title']} -
-

- ${album['parent_title']} · ${album['track_count']} track${'s' if album['track_count'] > 1 else ''} -

- % if artist['title'].lower() != 'various artists': -

- ${album['summary'][:200] + (album['summary'][200:] and '...')} -

- % endif -
+
+ + + + + + + + + - -
+ ${album['title']} +
+

+ ${album['parent_title']} · ${album['track_count']} track${'s' if album['track_count'] > 1 else ''} +

+ % if artist['title'].lower() != 'various artists': +

+ ${album['summary'][:200] + (album['summary'][200:] and '...')} +

+ % endif +
-
-
+
+
+
- -