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
|
from datetime import date, timedelta
|
||||||
import os
|
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']
|
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())
|
monday = today - timedelta(days=today.weekday())
|
||||||
previous_monday = monday - timedelta(days=7)
|
previous_monday = monday - timedelta(days=7)
|
||||||
next_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_week_events = create_events_from_span(previous_monday,
|
||||||
previous_monday + timedelta(days=6),
|
previous_monday + timedelta(days=6),
|
||||||
data_paths.members(),
|
id_to_person,
|
||||||
data_paths.mariages())
|
mariages)
|
||||||
this_week_events = create_events_from_span(monday,
|
this_week_events = create_events_from_span(monday,
|
||||||
monday + timedelta(days=6),
|
monday + timedelta(days=6),
|
||||||
data_paths.members(),
|
id_to_person,
|
||||||
data_paths.mariages())
|
mariages)
|
||||||
next_week_events = create_events_from_span(next_monday,
|
next_week_events = create_events_from_span(next_monday,
|
||||||
next_monday + timedelta(days=6),
|
next_monday + timedelta(days=6),
|
||||||
data_paths.members(),
|
id_to_person,
|
||||||
data_paths.mariages())
|
mariages)
|
||||||
return previous_week_events, this_week_events, next_week_events
|
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, ''
|
return -1, ''
|
||||||
|
|
||||||
|
|
||||||
def create_events_from_span(start: date, end: date, members_file: str, mariages_file: str) -> list:
|
def create_events_from_span(start: date, end: date, id_to_person: dict, mariages: list) -> list:
|
||||||
id_to_person = load_persons_to_dict(members_file)
|
|
||||||
mariages = load_mariage_to_list(mariages_file)
|
|
||||||
cur_year = start.year
|
cur_year = start.year
|
||||||
|
|
||||||
events = []
|
events = []
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue