trip: include transit airport cities in destination timezone list
Transit countries (e.g. Madrid on the Peru trip) were already included in trip.countries via flight data, but get_destination_timezones only iterated trip.locations() which comes from accommodation/conferences/events. Now also extract airport cities from flights and append any that aren't already covered by a stay, using the airport coordinates for timezone lookup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5e2fb72fef
commit
b3975dad3a
1 changed files with 37 additions and 1 deletions
38
web_view.py
38
web_view.py
|
|
@ -887,10 +887,46 @@ def get_destination_timezones(trip: Trip) -> list[StrDict]:
|
|||
if candidate:
|
||||
per_location[key].append(candidate)
|
||||
|
||||
# Also collect airport locations from flights, for transit countries
|
||||
flight_locations: list[tuple[str, Country]] = []
|
||||
seen_flight_keys: set[tuple[str, str]] = set()
|
||||
for item in trip.travel:
|
||||
if item.get("type") != "flight":
|
||||
continue
|
||||
for airport_key in ("from_airport", "to_airport"):
|
||||
airport = item.get(airport_key)
|
||||
if not isinstance(airport, dict):
|
||||
continue
|
||||
city = airport.get("city")
|
||||
country_code = airport.get("country")
|
||||
if not isinstance(city, str) or not isinstance(country_code, str):
|
||||
continue
|
||||
if country_code == "gb":
|
||||
continue
|
||||
key = (city, country_code.lower())
|
||||
lat = airport.get("latitude")
|
||||
lon = airport.get("longitude")
|
||||
if isinstance(lat, (int, float)) and isinstance(lon, (int, float)):
|
||||
location_coords.setdefault(key, (float(lat), float(lon)))
|
||||
if key not in seen_flight_keys:
|
||||
seen_flight_keys.add(key)
|
||||
flight_country = agenda.get_country(country_code)
|
||||
if flight_country:
|
||||
flight_locations.append((city, flight_country))
|
||||
|
||||
existing_location_keys = {
|
||||
(loc, c.alpha_2.lower()) for loc, c in trip.locations()
|
||||
}
|
||||
all_locations = list(trip.locations()) + [
|
||||
(city, country)
|
||||
for city, country in flight_locations
|
||||
if (city, country.alpha_2.lower()) not in existing_location_keys
|
||||
]
|
||||
|
||||
destination_times: list[StrDict] = []
|
||||
trip_end = trip.end or trip.start
|
||||
|
||||
for location, country in trip.locations():
|
||||
for location, country in all_locations:
|
||||
country_code = country.alpha_2.lower()
|
||||
key = (location, country_code)
|
||||
timezone_name = None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue