From f7b543a41a44ac9a3e4ca4b528f13c4843080bb1 Mon Sep 17 00:00:00 2001 From: cyril Date: Wed, 17 Jun 2026 10:42:57 +0200 Subject: [PATCH] Add celebrations + fixes --- .gitignore | 3 ++- src/celebration.py | 21 +++++++++++++++ src/email_sender.py | 12 ++++++--- src/event.py | 66 ++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 src/celebration.py diff --git a/.gitignore b/.gitignore index 0889879..be6c946 100644 --- a/.gitignore +++ b/.gitignore @@ -142,4 +142,5 @@ cython_debug/ # Specific src/data/* -html_template/*.psd \ No newline at end of file +html_template/*.psd +.configs/ \ No newline at end of file diff --git a/src/celebration.py b/src/celebration.py new file mode 100644 index 0000000..cbcdf24 --- /dev/null +++ b/src/celebration.py @@ -0,0 +1,21 @@ +from datetime import date + +celeb_types = ['O'] # O = Ordination + + +class Celebration: + def __init__(self, id_a: int, event_date: date, celeb_type: str): + self._id_a = id_a + self._date = event_date + if celeb_type not in celeb_types: + raise ValueError('{} is not in {}'.format(celeb_type, celeb_types)) + self._celeb_type = celeb_type + + def event_date(self): + return self._date + + def id_a(self): + return self._id_a + + def celeb_type(self): + return self._celeb_type diff --git a/src/email_sender.py b/src/email_sender.py index 7319b9d..6024c2a 100644 --- a/src/email_sender.py +++ b/src/email_sender.py @@ -7,7 +7,7 @@ from argparse import ArgumentParser from datetime import date, timedelta import os -from event import create_events_from_span, load_persons_to_dict, load_mariage_to_list +from event import create_events_from_span, load_persons_to_dict, load_mariage_to_list, load_celebrations_to_list week_days = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'] @@ -233,19 +233,23 @@ def get_events(data_paths: DataPaths): id_to_person = load_persons_to_dict(data_paths.members()) mariages = load_mariage_to_list(data_paths.mariages()) + celebrations = load_celebrations_to_list(data_paths.mariages()) previous_week_events = create_events_from_span(previous_monday, previous_monday + timedelta(days=6), id_to_person, - mariages) + mariages, + celebrations) this_week_events = create_events_from_span(monday, monday + timedelta(days=6), id_to_person, - mariages) + mariages, + celebrations) next_week_events = create_events_from_span(next_monday, next_monday + timedelta(days=6), id_to_person, - mariages) + mariages, + celebrations) return previous_week_events, this_week_events, next_week_events diff --git a/src/event.py b/src/event.py index fc260c5..b323efd 100644 --- a/src/event.py +++ b/src/event.py @@ -1,9 +1,14 @@ from datetime import date from person import Person from mariage import Mariage +from celebration import Celebration - -event_types = ['N', 'M', 'A', 'D'] +# N = Naissance +# M = Marriage +# A = Autre union officielle +# D = Décès +# O = Ordination +event_types = ['N', 'M', 'A', 'D', 'O'] class Event: @@ -55,6 +60,13 @@ class Event: y, 's' if y > 1 else '' ) + + if self._type == 'O': + return '{} a été ordonné il y a {} an{}'.format( + self._p_a.formatted_name(), + y, + 's' if y > 1 else '' + ) return '{}{} décédé{} il y a {} an{}'.format( self._p_a.formatted_name(), @@ -114,6 +126,10 @@ def load_mariage_to_list(mariages_file: str) -> list: if first_line: first_line = False continue + + if "Ordination" in line: + continue + line.strip() infos = line.split(',') @@ -143,6 +159,32 @@ def load_mariage_to_list(mariages_file: str) -> list: return mariage_lst +def load_celebrations_to_list(mariages_file: str) -> list: + celebrations = [] + first_line = True + with open(mariages_file, 'r', encoding='utf-8') as mariages: + for line in mariages: + if first_line: + first_line = False + continue + line.strip() + + celeb = None + if "Ordination" in line: + # DD/MM/YYYY,NAME,FIRSTNAME,Ordination,DoB + infos = line.split(',') + doe = infos[0].split('/') + name = infos[1] + first_name = infos[2] + dob = infos[4].strip()[4:].split('/') + id_person = Person.get_id(first_name, name, date(int(dob[2]), int(dob[1]), int(dob[0]))) + celeb = Celebration(id_person, date(int(doe[2]), int(doe[1]), int(doe[0])), 'O') + + if celeb is not None: + celebrations.append(celeb) + return celebrations + + def find_significant_other(mariages: list, uid: int) -> (int, str): matches = sorted([m for m in mariages if m.in_this_union(uid)], key=lambda union: union.event_date()) if not matches: @@ -150,7 +192,7 @@ def find_significant_other(mariages: list, uid: int) -> (int, str): return matches[-1].get_so(uid), matches[-1].union() -def create_events_from_span(start: date, end: date, id_to_person: dict, mariages: list) -> list: +def create_events_from_span(start: date, end: date, id_to_person: dict, mariages: list, celebrations: list) -> list: cur_year = start.year events = [] @@ -159,6 +201,9 @@ def create_events_from_span(start: date, end: date, id_to_person: dict, mariages so, union = find_significant_other(mariages, p.get_hash_id()) if so == p.get_hash_id(): print(f"What ??? {so}") + if so != -1 and so not in id_to_person.keys(): + print(so, "Missing SO in members") + so = -1 if not p.is_dead(): birth = p.birth() birth_in_year = date(cur_year, birth.month, birth.day) @@ -200,4 +245,19 @@ def create_events_from_span(start: date, end: date, id_to_person: dict, mariages id_to_person[m.id_a()], id_to_person[m.id_b()]) events.append(e) + for c in celebrations: + m_date = c.event_date() + date_in_year = date(cur_year, m_date.month, m_date.day) + if start <= date_in_year <= end: + e = Event(c.celeb_type(), m_date, date_in_year, + id_to_person[c.id_a()]) + events.append(e) + + date_in_year = date(cur_year + 1, m_date.month, m_date.day) + if start <= date_in_year <= end: + e = Event(c.celeb_type(), m_date, date_in_year, + id_to_person[c.id_a()]) + events.append(e) + + return events