diff --git a/flatisfy/data.py b/flatisfy/data.py index 698bd63..20de512 100644 --- a/flatisfy/data.py +++ b/flatisfy/data.py @@ -83,8 +83,13 @@ def load_data(model, constraint, config): get_session = database.init_db(config["database"], config["search_index"]) results = [] with get_session() as session: + areas = [] + # Get areas to fetch from, using postal codes for postal_code in constraint["postal_codes"]: - area = data_files.french_postal_codes_to_iso_3166(postal_code) + areas.append(data_files.french_postal_codes_to_iso_3166(postal_code)) + # Load data for each area + areas = list(set(areas)) + for area in areas: results.extend( session.query(model) .filter(model.area == area).all()