import json from pathlib import Path from models.country import Country def load_circuits_json(file_path: Path, load_geo_data: bool=False) -> dict[str, Country]: with open(file_path) as f: return parse_circuits_json(json.load(f), load_geo_data) def parse_circuits_json(data: dict, load_geo_data: bool=False) -> dict[str, Country]: countries = {} for country_slug, country_data in data.items(): countries[country_slug] = Country.from_dict(country_slug, country_data) if load_geo_data: countries[country_slug].load_geo_json_data() return countries