diff --git a/flight-comparator/airports.py b/flight-comparator/airports.py index 08b785c..6b03c57 100644 --- a/flight-comparator/airports.py +++ b/flight-comparator/airports.py @@ -69,6 +69,13 @@ COUNTRY_NAME_TO_ISO = { } +# Airports missing from the OpenFlights dataset (opened or renamed after dataset was last updated). +# Keyed by ISO country code; dicts match the airports_by_country.json schema (iata/name/city/icao). +_MISSING_AIRPORTS: dict[str, list[dict]] = { + 'DE': [{'iata': 'BER', 'name': 'Berlin Brandenburg Airport', 'city': 'Berlin', 'icao': 'EDDB'}], +} + + def country_name_to_iso_code(country_name: str) -> Optional[str]: """ Convert country name to ISO 2-letter code. @@ -197,7 +204,12 @@ def get_airports_for_country(country_code: str) -> list[dict]: f"Available codes (sample): {', '.join(available)}..." ) - return airports_by_country[country_code] + result = list(airports_by_country[country_code]) + existing_iatas = {a['iata'] for a in result} + for extra in _MISSING_AIRPORTS.get(country_code, []): + if extra['iata'] not in existing_iatas: + result.append(extra) + return result def resolve_airport_list(country: Optional[str], from_airports: Optional[str]) -> list[dict]: @@ -233,11 +245,16 @@ def _all_airports_by_iata() -> dict: download_and_build_airport_data() with open(AIRPORTS_JSON_PATH, 'r', encoding='utf-8') as f: airports_by_country = json.load(f) - return { + result = { a['iata']: a for airports in airports_by_country.values() for a in airports } + for extras in _MISSING_AIRPORTS.values(): + for extra in extras: + if extra['iata'] not in result: + result[extra['iata']] = extra + return result def lookup_airport(iata: str) -> dict | None: