Add support for showing only current week
This commit is contained in:
parent
04b7c01509
commit
ef815b5284
2 changed files with 237 additions and 11 deletions
212
html_template/mail_onlyweek.html
Normal file
212
html_template/mail_onlyweek.html
Normal file
|
|
@ -0,0 +1,212 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>{GENEALETTER_NAME}</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
|
<style type="text/css">
|
||||||
|
/* FONTS */
|
||||||
|
@media screen {
|
||||||
|
@font-face {
|
||||||
|
font-family: "Open Sans";
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
src: local("Open Sans"), local("OpenSans"), url(https://fonts.gstatic.com/s/opensans/v13/cJZKeOuBrn4kERxqtaUH3ZBw1xU1rKptJj_0jans920.woff2) format("woff2");
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: "Open Sans";
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 700;
|
||||||
|
src: local("Open Sans Bold"), local("OpenSans-Bold"), url(https://fonts.gstatic.com/s/opensans/v13/k3k702ZOKiLJc3WVjuplzBampu5_7CjHW5spxoeN3Vs.woff2) format("woff2");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CLIENT-SPECIFIC STYLES */
|
||||||
|
body,
|
||||||
|
table,
|
||||||
|
td,
|
||||||
|
a {
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
-ms-text-size-adjust: 100%;
|
||||||
|
}
|
||||||
|
table,
|
||||||
|
td {
|
||||||
|
mso-table-lspace: 0pt;
|
||||||
|
mso-table-rspace: 0pt;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
-ms-interpolation-mode: bicubic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* RESET STYLES */
|
||||||
|
img {
|
||||||
|
border: 0;
|
||||||
|
height: auto;
|
||||||
|
line-height: 100%;
|
||||||
|
outline: none;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
border-collapse: collapse !important;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
height: 100% !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* iOS BLUE LINKS */
|
||||||
|
a[x-apple-data-detectors] {
|
||||||
|
color: inherit !important;
|
||||||
|
text-decoration: none !important;
|
||||||
|
font-size: inherit !important;
|
||||||
|
font-family: inherit !important;
|
||||||
|
font-weight: inherit !important;
|
||||||
|
line-height: inherit !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* MOBILE STYLES */
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
h1 {
|
||||||
|
font-size: 32px !important;
|
||||||
|
line-height: 32px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
td.genea_row {
|
||||||
|
padding: 2px 5px 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.genea_header {
|
||||||
|
padding: 3px 5px 0px;
|
||||||
|
font-size: 90%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.min_info {
|
||||||
|
font-size: 90%;
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.day_row {
|
||||||
|
padding: 3px 5px 0px;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 110%;
|
||||||
|
color: {GENEALETTER_MAIN_COLOR};
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ANDROID CENTER FIX */
|
||||||
|
div[style*="margin: 16px 0;"] {
|
||||||
|
margin: 0 !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body style="background-color: {GENEALETTER_SECOND_COLOR}; margin: 0 !important; padding: 0 !important;">
|
||||||
|
<!-- HIDDEN PREHEADER TEXT -->
|
||||||
|
<div style="display: none; font-size: 1px; color: #fefefe; line-height: 1px; font-family: 'Open Sans', 'OpenSans', Segoe UI, Helvetica, Arial, sans-serif; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden;">
|
||||||
|
{GENEALETTER_NAME}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="font-family: 'Open Sans', 'OpenSans', Segoe UI, Helvetica, Arial, sans-serif;">
|
||||||
|
<!-- LOGO -->
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="{GENEALETTER_MAIN_COLOR}" align="center">
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
||||||
|
<tr>
|
||||||
|
<td align="center" valign="top" width="600">
|
||||||
|
<![endif]-->
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
|
||||||
|
<tr>
|
||||||
|
<td align="center" valign="top" style="padding: 15px 10px 15px 10px;">
|
||||||
|
<img alt="Logo" src="{LogoAddress}" width="450" height="75" style="display: block; width: 300px; max-width: 450px; min-width: 75px; border="0">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<![endif]-->
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<!-- HERO -->
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="{GENEALETTER_MAIN_COLOR}" align="center" style="padding: 0px 10px 0px 10px;">
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
||||||
|
<tr>
|
||||||
|
<td align="center" valign="top" width="600">
|
||||||
|
<![endif]-->
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="#ffffff" align="center" valign="top" style="padding: 20px 20px 20px 20px; border-radius: 20px 20px 0px 0px; color: #2a2f34; font-weight: 400; letter-spacing: 0px;">
|
||||||
|
<h1 style="font-size: 32px; font-weight: 400; margin: 0;">{Main_Title}</h1>
|
||||||
|
<h2 style="font-size: 18px; font-weight: 200; margin-top: 5px; margin-bottom: 0px;">{Sub_Title}</h2>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<![endif]-->
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<!-- COPY BLOCK -->
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="{GENEALETTER_SECOND_COLOR}" align="center" style="padding: 0px 10px 0px 10px;">
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
||||||
|
<tr>
|
||||||
|
<td align="center" valign="top" width="600">
|
||||||
|
<![endif]-->
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
|
||||||
|
<!-- COPY -->
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="#ffffff" align="center" style="padding: 0px 30px 20px 30px; color: #2b342a; font-size: 16px; font-weight: 400; text-align: center; border-radius: 0px 0px 20px 20px;">
|
||||||
|
<table style="width: 100%;">
|
||||||
|
{EVENTS_CURRENT}
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<![endif]-->
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<!-- FOOTER -->
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="{GENEALETTER_SECOND_COLOR}" align="center" style="padding: 0px 10px 0px 10px;">
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
||||||
|
<tr>
|
||||||
|
<td align="center" valign="top" width="600">
|
||||||
|
<![endif]-->
|
||||||
|
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
|
||||||
|
<!-- NAVIGATION -->
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="{GENEALETTER_SECOND_COLOR}" align="center" style="padding: 30px 30px 30px 30px; color: #9ba5ae; font-size: 14px; font-weight: 400; line-height: 18px;">
|
||||||
|
<p style="margin: 0;">
|
||||||
|
Cet email vous est envoyé par Cyril NOVEL<br />
|
||||||
|
parce que vous êtes inscrit sur la liste de diffusion de {GENEALETTER_NAME}.<br />
|
||||||
|
Des questions ou des commentaires ? Envoyez un email à <a href="mailto:{GENEALETTER_RESPONSE}" style="color: {GENEALETTER_MAIN_COLOR};">{GENEALETTER_NAME}</a>.
|
||||||
|
</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<![endif]-->
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -28,12 +28,13 @@ class DataPaths:
|
||||||
|
|
||||||
|
|
||||||
class LetterOptions:
|
class LetterOptions:
|
||||||
def __init__(self, name, response_email, logo_url, hex_main_color, hex_second_color):
|
def __init__(self, name, response_email, logo_url, hex_main_color, hex_second_color, only_current_week):
|
||||||
self._name = name
|
self._name = name
|
||||||
self._response_email = response_email
|
self._response_email = response_email
|
||||||
self._logo_url = logo_url
|
self._logo_url = logo_url
|
||||||
self._main_color = hex_main_color
|
self._main_color = hex_main_color
|
||||||
self._second_color = hex_second_color
|
self._second_color = hex_second_color
|
||||||
|
self._only_current_week = only_current_week
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
return self._name
|
return self._name
|
||||||
|
|
@ -50,6 +51,9 @@ class LetterOptions:
|
||||||
def secondary_color_hex(self):
|
def secondary_color_hex(self):
|
||||||
return self._second_color
|
return self._second_color
|
||||||
|
|
||||||
|
def only_cur_week(self):
|
||||||
|
return self._only_current_week
|
||||||
|
|
||||||
|
|
||||||
class Mailer:
|
class Mailer:
|
||||||
def __init__(self, server, user, password):
|
def __init__(self, server, user, password):
|
||||||
|
|
@ -104,7 +108,10 @@ class EmailSender:
|
||||||
|
|
||||||
def create_html_templated(events_previous, events_current, events_next, letter: LetterOptions):
|
def create_html_templated(events_previous, events_current, events_next, letter: LetterOptions):
|
||||||
directory = os.path.dirname(os.path.realpath(__file__))
|
directory = os.path.dirname(os.path.realpath(__file__))
|
||||||
template_path = os.path.join(directory, '..', 'html_template', 'mail.html')
|
if letter.only_cur_week():
|
||||||
|
template_path = os.path.join(directory, '..', 'html_template', 'mail_onlyweek.html')
|
||||||
|
else:
|
||||||
|
template_path = os.path.join(directory, '..', 'html_template', 'mail.html')
|
||||||
with open(template_path, 'r', encoding='utf-8') as tmp:
|
with open(template_path, 'r', encoding='utf-8') as tmp:
|
||||||
mail = tmp.read()
|
mail = tmp.read()
|
||||||
mail = mail.replace('{LogoAddress}', letter.logo_url())
|
mail = mail.replace('{LogoAddress}', letter.logo_url())
|
||||||
|
|
@ -118,9 +125,10 @@ def create_html_templated(events_previous, events_current, events_next, letter:
|
||||||
f'du {wk_and_span[1].day} {months[wk_and_span[1].month - 1]}'
|
f'du {wk_and_span[1].day} {months[wk_and_span[1].month - 1]}'
|
||||||
f' au {wk_and_span[2].day} {months[wk_and_span[2].month - 1]}')
|
f' au {wk_and_span[2].day} {months[wk_and_span[2].month - 1]}')
|
||||||
|
|
||||||
mail = mail.replace('{EVENTS_PREVIOUS}', create_html_string_for_week(events_previous))
|
if not letter.only_cur_week():
|
||||||
|
mail = mail.replace('{EVENTS_PREVIOUS}', create_html_string_for_week(events_previous))
|
||||||
|
mail = mail.replace('{EVENTS_NEXT}', create_html_string_for_week(events_next))
|
||||||
mail = mail.replace('{EVENTS_CURRENT}', create_html_string_for_week(events_current))
|
mail = mail.replace('{EVENTS_CURRENT}', create_html_string_for_week(events_current))
|
||||||
mail = mail.replace('{EVENTS_NEXT}', create_html_string_for_week(events_next))
|
|
||||||
|
|
||||||
return mail
|
return mail
|
||||||
|
|
||||||
|
|
@ -131,15 +139,19 @@ def create_plain_email(events_previous, events_current, events_next, letter: Let
|
||||||
mail_plain += f'du {wk_and_span[1].day} {months[wk_and_span[1].month - 1]}' \
|
mail_plain += f'du {wk_and_span[1].day} {months[wk_and_span[1].month - 1]}' \
|
||||||
f' au {wk_and_span[2].day} {months[wk_and_span[2].month - 1]}\n'
|
f' au {wk_and_span[2].day} {months[wk_and_span[2].month - 1]}\n'
|
||||||
mail_plain += '\n\n'
|
mail_plain += '\n\n'
|
||||||
mail_plain += 'Semaine précédente :\n'
|
|
||||||
mail_plain += create_plain_string_for_week(events_previous)
|
if not letter.only_cur_week():
|
||||||
mail_plain += '\n'
|
mail_plain += 'Semaine précédente :\n'
|
||||||
|
mail_plain += create_plain_string_for_week(events_previous)
|
||||||
|
mail_plain += '\n'
|
||||||
mail_plain += 'Cette semaine :\n'
|
mail_plain += 'Cette semaine :\n'
|
||||||
mail_plain += create_plain_string_for_week(events_current)
|
mail_plain += create_plain_string_for_week(events_current)
|
||||||
mail_plain += '\n'
|
mail_plain += '\n'
|
||||||
mail_plain += 'Semaine suivante :\n'
|
if not letter.only_cur_week():
|
||||||
mail_plain += create_plain_string_for_week(events_next)
|
mail_plain += 'Semaine suivante :\n'
|
||||||
mail_plain += '\n\n'
|
mail_plain += create_plain_string_for_week(events_next)
|
||||||
|
mail_plain += '\n'
|
||||||
|
mail_plain += '\n'
|
||||||
|
|
||||||
mail_plain += 'Cet email vous est envoyé par Cyril NOVEL parce que vous êtes inscrit sur la ' \
|
mail_plain += 'Cet email vous est envoyé par Cyril NOVEL parce que vous êtes inscrit sur la ' \
|
||||||
'liste de diffusion de {}.\n'.format(letter.name())
|
'liste de diffusion de {}.\n'.format(letter.name())
|
||||||
|
|
@ -246,11 +258,13 @@ def get_week_number_and_span():
|
||||||
def load_config(config_file) -> (LetterOptions, Mailer, DataPaths, str):
|
def load_config(config_file) -> (LetterOptions, Mailer, DataPaths, str):
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(config_file, encoding='utf-8')
|
config.read(config_file, encoding='utf-8')
|
||||||
|
only_cur_wk = config.has_option('Letter', 'only_current_week') and config['Letter']['only_current_week'] == 'yes'
|
||||||
letter_opts = LetterOptions(config['Letter']['name'],
|
letter_opts = LetterOptions(config['Letter']['name'],
|
||||||
config['Letter']['response_email'],
|
config['Letter']['response_email'],
|
||||||
config['Letter']['logo_url'],
|
config['Letter']['logo_url'],
|
||||||
config['Letter']['color_main'],
|
config['Letter']['color_main'],
|
||||||
config['Letter']['color_second'])
|
config['Letter']['color_second'],
|
||||||
|
only_cur_wk)
|
||||||
mailer = Mailer(config['Mailer']['smtp_server'],
|
mailer = Mailer(config['Mailer']['smtp_server'],
|
||||||
config['Mailer']['user'],
|
config['Mailer']['user'],
|
||||||
config['Mailer']['password'])
|
config['Mailer']['password'])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue