Load data only once
This commit is contained in:
parent
ccb11e2be4
commit
04b7c01509
2 changed files with 12 additions and 10 deletions
|
|
@ -7,7 +7,7 @@ from argparse import ArgumentParser
|
|||
from datetime import date, timedelta
|
||||
import os
|
||||
|
||||
from event import create_events_from_span
|
||||
from event import create_events_from_span, load_persons_to_dict, load_mariage_to_list
|
||||
|
||||
|
||||
week_days = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche']
|
||||
|
|
@ -218,18 +218,22 @@ def get_events(data_paths: DataPaths):
|
|||
monday = today - timedelta(days=today.weekday())
|
||||
previous_monday = monday - timedelta(days=7)
|
||||
next_monday = monday + timedelta(days=7)
|
||||
|
||||
id_to_person = load_persons_to_dict(data_paths.members())
|
||||
mariages = load_mariage_to_list(data_paths.mariages())
|
||||
|
||||
previous_week_events = create_events_from_span(previous_monday,
|
||||
previous_monday + timedelta(days=6),
|
||||
data_paths.members(),
|
||||
data_paths.mariages())
|
||||
id_to_person,
|
||||
mariages)
|
||||
this_week_events = create_events_from_span(monday,
|
||||
monday + timedelta(days=6),
|
||||
data_paths.members(),
|
||||
data_paths.mariages())
|
||||
id_to_person,
|
||||
mariages)
|
||||
next_week_events = create_events_from_span(next_monday,
|
||||
next_monday + timedelta(days=6),
|
||||
data_paths.members(),
|
||||
data_paths.mariages())
|
||||
id_to_person,
|
||||
mariages)
|
||||
return previous_week_events, this_week_events, next_week_events
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -150,9 +150,7 @@ def find_significant_other(mariages: list, uid: int) -> (int, str):
|
|||
return -1, ''
|
||||
|
||||
|
||||
def create_events_from_span(start: date, end: date, members_file: str, mariages_file: str) -> list:
|
||||
id_to_person = load_persons_to_dict(members_file)
|
||||
mariages = load_mariage_to_list(mariages_file)
|
||||
def create_events_from_span(start: date, end: date, id_to_person: dict, mariages: list) -> list:
|
||||
cur_year = start.year
|
||||
|
||||
events = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue