fix: enrich route destination names from airport DB when not stored

Specific-airports mode scans never resolved full airport names — they
stored the IATA code as destination_name. Fixed in two places:

- airports.py: add lookup_airport(iata) cached helper
- api_server.py: enrich destination_name/city on the fly in the routes
  endpoint when the stored value equals the IATA code (fixes all past scans)
- scan_processor.py: resolve airport names at scan time in specific-airports
  mode using lookup_airport (fixes future scans at the DB level)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 21:04:46 +01:00
parent 0a2fed7465
commit ef5a27097d
3 changed files with 46 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ Handles loading and filtering airport data from OpenFlights dataset.
import json
import csv
from functools import lru_cache
from pathlib import Path
from typing import Optional
import urllib.request
@@ -225,6 +226,25 @@ def resolve_airport_list(country: Optional[str], from_airports: Optional[str]) -
raise ValueError("Either --country or --from must be provided")
@lru_cache(maxsize=1)
def _all_airports_by_iata() -> dict:
"""Return {iata: airport_dict} for every airport. Cached after first load."""
if not AIRPORTS_JSON_PATH.exists():
download_and_build_airport_data()
with open(AIRPORTS_JSON_PATH, 'r', encoding='utf-8') as f:
airports_by_country = json.load(f)
return {
a['iata']: a
for airports in airports_by_country.values()
for a in airports
}
def lookup_airport(iata: str) -> dict | None:
"""Look up a single airport by IATA code. Returns None if not found."""
return _all_airports_by_iata().get(iata.upper())
if __name__ == "__main__":
# Build the dataset if run directly
download_and_build_airport_data(force_rebuild=True)