diff --git a/agenda/busy.py b/agenda/busy.py index 72793c3..eb60793 100644 --- a/agenda/busy.py +++ b/agenda/busy.py @@ -87,7 +87,7 @@ def get_location_for_date( bookings: list[dict], accommodations: list[dict], airports: dict, -) -> tuple[str | None, pycountry.db.Country | None]: +) -> tuple[str, pycountry.db.Country | None]: """Get location (city, country) for a specific date using travel history.""" # UK airports that indicate being home uk_airports = {"LHR", "LGW", "STN", "LTN", "BRS", "BHX", "MAN", "EDI", "GLA"} @@ -135,22 +135,10 @@ def get_location_for_date( destination_airport = flight["to"] if destination_airport in uk_airports: - # When on a trip, show the actual location even for UK airports - airport_info = airports.get(destination_airport) - if airport_info: - location_name = airport_info.get( - "city", - airport_info.get("name", "London"), - ) - trip_most_recent_location = ( - location_name, - get_country("gb"), - ) - else: - trip_most_recent_location = ( - "London", - get_country("gb"), - ) + trip_most_recent_location = ( + "Bristol", + get_country("gb"), + ) else: airport_info = airports.get(destination_airport) if airport_info: @@ -189,9 +177,8 @@ def get_location_for_date( ): trip_most_recent_date = acc_date if acc.get("country") == "gb": - # When on a trip, show the actual location even for UK accommodations trip_most_recent_location = ( - acc.get("location", "London"), + "Bristol", get_country("gb"), ) else: @@ -200,28 +187,14 @@ def get_location_for_date( get_country(acc.get("country", "gb")), ) - # Return the most recent location within the trip, or fallback to trip location by date + # Return the most recent location within the trip, or fallback to first trip location if trip_most_recent_location: return trip_most_recent_location - # Fallback: determine location based on trip progression and date + # Fallback to first location if no specific location found locations = trip.locations() if locations: - # If only one location, use it (when on a trip, always show the location) - if len(locations) == 1: - city, country = locations[0] - return (city, country) - - # Multiple locations: use progression through the trip - trip_duration = (trip.end - trip.start).days + 1 - days_into_trip = (target_date - trip.start).days - - # Simple progression: first half at first location, second half at last location - if days_into_trip <= trip_duration // 2: - city, country = locations[0] - else: - city, country = locations[-1] - + city, country = locations[0] return (city, country) # Find most recent flight or accommodation before this date @@ -263,7 +236,7 @@ def get_location_for_date( # If arriving at UK airport, assume back home in Bristol if destination_airport in uk_airports: - most_recent_location = (None, get_country("gb")) + most_recent_location = ("Bristol", get_country("gb")) else: # Get destination airport location for non-UK arrivals airport_info = airports.get(destination_airport) @@ -294,7 +267,7 @@ def get_location_for_date( most_recent_date = acc_date # For UK accommodation, use Bristol as location if acc.get("country") == "gb": - most_recent_location = (None, get_country("gb")) + most_recent_location = ("Bristol", get_country("gb")) else: most_recent_location = ( acc.get("location", "Unknown"), @@ -309,10 +282,13 @@ def get_location_for_date( if locations: final_city, final_country = locations[-1] days_since_trip = (target_date - trip.end).days - + # If trip ended in UK, you should be home now - if hasattr(final_country, "alpha_2") and final_country.alpha_2 == "GB": - return (None, get_country("gb")) + if ( + hasattr(final_country, "alpha_2") + and final_country.alpha_2 == "GB" + ): + return ("Bristol", get_country("gb")) # For short trips to nearby countries or international trips # (ended >=1 day ago), assume returned home if no subsequent travel data @@ -321,35 +297,20 @@ def get_location_for_date( and hasattr(final_country, "alpha_2") and ( # European countries (close by rail/ferry) - final_country.alpha_2 - in {"BE", "NL", "FR", "DE", "CH", "AT", "IT", "ES"} + final_country.alpha_2 in {"BE", "NL", "FR", "DE", "CH", "AT", "IT", "ES"} # Nearby Balkan countries - or final_country.alpha_2 - in { - "GR", - "AL", - "XK", - "HR", - "SI", - "MK", - "BA", - "ME", - "RS", - "BG", - "RO", - } + or final_country.alpha_2 in {"GR", "AL", "XK", "HR", "SI", "MK", "BA", "ME", "RS", "BG", "RO"} # International trips (assume return home after trip ends) - or final_country.alpha_2 - in {"US", "CA", "IN", "JP", "CN", "AU", "NZ", "BR", "AR", "ZA"} + or final_country.alpha_2 in {"US", "CA", "IN", "JP", "CN", "AU", "NZ", "BR", "AR", "ZA"} ) ): - return (None, get_country("gb")) + return ("Bristol", get_country("gb")) # Return most recent location or default to Bristol if most_recent_location: return most_recent_location - return (None, get_country("gb")) + return ("Bristol", get_country("gb")) def weekends( diff --git a/templates/weekends.html b/templates/weekends.html index b96f09a..82bdd08 100644 --- a/templates/weekends.html +++ b/templates/weekends.html @@ -47,7 +47,9 @@ {% if extra_class %}