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:
@@ -1430,7 +1430,8 @@ async def get_scan_routes(
|
||||
rows = cursor.fetchall()
|
||||
conn.close()
|
||||
|
||||
# Convert to Route models
|
||||
# Convert to Route models, enriching name/city from airport DB when missing
|
||||
lookup = _iata_lookup()
|
||||
routes = []
|
||||
for row in rows:
|
||||
# Parse airlines JSON
|
||||
@@ -1439,12 +1440,22 @@ async def get_scan_routes(
|
||||
except:
|
||||
airlines = []
|
||||
|
||||
dest = row[2]
|
||||
dest_name = row[3] or dest
|
||||
dest_city = row[4] or ''
|
||||
|
||||
# If name was never resolved (stored as IATA code), look it up now
|
||||
if dest_name == dest:
|
||||
airport = lookup.get(dest, {})
|
||||
dest_name = airport.get('name', dest)
|
||||
dest_city = airport.get('city', dest_city)
|
||||
|
||||
routes.append(Route(
|
||||
id=row[0],
|
||||
scan_id=row[1],
|
||||
destination=row[2],
|
||||
destination_name=row[3],
|
||||
destination_city=row[4],
|
||||
destination=dest,
|
||||
destination_name=dest_name,
|
||||
destination_city=dest_city,
|
||||
flight_count=row[5],
|
||||
airlines=airlines,
|
||||
min_price=row[7],
|
||||
@@ -1712,6 +1723,12 @@ def get_airport_data():
|
||||
return airports
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def _iata_lookup() -> dict:
|
||||
"""Return {iata: airport_dict} built from get_airport_data(). Cached."""
|
||||
return {a['iata']: a for a in get_airport_data()}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
|
||||
Reference in New Issue
Block a user