import base64 import html from urllib.parse import urlencode from .recap_email import document def description(entry): if entry['type'] == 'movie': return f"Movie · {entry['year']}" if entry.get('year') else 'Movie' seasons = sorted({item['season'] for item in entry['items'] if isinstance(item.get('season'), int)}) count = len(entry['items']) labels = ', '.join('Specials' if value == 0 else str(value) for value in seasons[:8]) suffix = f" · {'Season' if len(seasons) == 1 else 'Seasons'} {labels}" if labels else '' return f"{count} new {'episode' if count == 1 else 'episodes'}{suffix}" def render_confirmation(username, url): intro = f"Hi {username}, confirm your email to receive new arrivals, featured picks and announcements from Grizzlyflix." return {'subject': 'Confirm your Grizzlyflix newsletter subscription', 'body_text': f'{intro}\n\nConfirm newsletter subscription: {url}\n\nThis link expires in 24 hours. If you did not request this, ignore this email.', 'body_html': document(title='Your next watch starts here.', intro=intro, content='
A weekly look at new movies and TV updates, with posters and links to watch.
', action='Confirm newsletter subscription', url=url, kicker='NEW ON GRIZZLYFLIX', footer='This link expires in 24 hours. If you did not request this, ignore this email.')} def render(content, images, public_url, playback_url, unsubscribe_url, *, preview=False, test=False): esc = html.escape titles = [entry for entry in content['titles'] if entry['selected']] body, lines, attachments = [], [], [] intro = str(content.get('intro') or '').strip() if intro: body.append(f'{esc(intro).replace(chr(10), "
")}
{esc(overview)}
' if overview and entry['featured'] else '' body.append(f'''| {poster} |
{esc(entry['title'])}{esc(details)} {copy} Watch on Grizzlyflix ↗ |
Your next discovery is waiting in Grizzlyflix.
') period = f"{content['period_start'][:10]} to {content['period_end'][:10]} · UTC" footer = f'You subscribed to the Grizzlyflix newsletter.