diff --git a/html_template/mail_onlyweek.html b/html_template/mail_onlyweek.html
new file mode 100644
index 0000000..83afc06
--- /dev/null
+++ b/html_template/mail_onlyweek.html
@@ -0,0 +1,212 @@
+
+
+
+ {GENEALETTER_NAME}
+
+
+
+
+
+
+
+
+ {GENEALETTER_NAME}
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+ {Main_Title}
+ {Sub_Title}
+ |
+
+
+
+ |
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+ |
+
+ Cet email vous est envoyé par Cyril NOVEL
+ parce que vous êtes inscrit sur la liste de diffusion de {GENEALETTER_NAME}.
+ Des questions ou des commentaires ? Envoyez un email à {GENEALETTER_NAME}.
+
+ |
+
+
+
+ |
+
+
+
+
diff --git a/src/email_sender.py b/src/email_sender.py
index 675dff0..7319b9d 100644
--- a/src/email_sender.py
+++ b/src/email_sender.py
@@ -28,12 +28,13 @@ class DataPaths:
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._response_email = response_email
self._logo_url = logo_url
self._main_color = hex_main_color
self._second_color = hex_second_color
+ self._only_current_week = only_current_week
def name(self):
return self._name
@@ -50,6 +51,9 @@ class LetterOptions:
def secondary_color_hex(self):
return self._second_color
+ def only_cur_week(self):
+ return self._only_current_week
+
class Mailer:
def __init__(self, server, user, password):
@@ -104,7 +108,10 @@ class EmailSender:
def create_html_templated(events_previous, events_current, events_next, letter: LetterOptions):
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:
mail = tmp.read()
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' 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_NEXT}', create_html_string_for_week(events_next))
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]}' \
f' au {wk_and_span[2].day} {months[wk_and_span[2].month - 1]}\n'
mail_plain += '\n\n'
- mail_plain += 'Semaine précédente :\n'
- mail_plain += create_plain_string_for_week(events_previous)
- mail_plain += '\n'
+
+ if not letter.only_cur_week():
+ 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 += create_plain_string_for_week(events_current)
mail_plain += '\n'
- mail_plain += 'Semaine suivante :\n'
- mail_plain += create_plain_string_for_week(events_next)
- mail_plain += '\n\n'
+ if not letter.only_cur_week():
+ mail_plain += 'Semaine suivante :\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 ' \
'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):
config = configparser.ConfigParser()
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'],
config['Letter']['response_email'],
config['Letter']['logo_url'],
config['Letter']['color_main'],
- config['Letter']['color_second'])
+ config['Letter']['color_second'],
+ only_cur_wk)
mailer = Mailer(config['Mailer']['smtp_server'],
config['Mailer']['user'],
config['Mailer']['password'])