diff --git a/agenda/trip.py b/agenda/trip.py index bf110b4..946c3ac 100644 --- a/agenda/trip.py +++ b/agenda/trip.py @@ -211,26 +211,6 @@ def add_coordinates_for_unbooked_flights( ) -def stations_from_travel(t: StrDict) -> list[StrDict]: - """Stations from train journey.""" - station_list = [t["from_station"], t["to_station"]] - for leg in t["legs"]: - station_list.append(leg["from_station"]) - station_list.append(leg["to_station"]) - - return station_list - - -def process_station_list(station_list: list[StrDict]) -> StrDict: - """Proess sation list.""" - stations = {} - for s in station_list: - if s["name"] in stations: - continue - stations[s["name"]] = s - return stations - - def get_locations(trip: Trip) -> dict[str, StrDict]: """Collect locations of all travel locations in trip.""" locations: dict[str, StrDict] = { @@ -243,7 +223,10 @@ def get_locations(trip: Trip) -> dict[str, StrDict]: for t in trip.travel: match t["type"]: case "train": - station_list += stations_from_travel(t) + station_list += [t["from_station"], t["to_station"]] + for leg in t["legs"]: + station_list.append(leg["from_station"]) + station_list.append(leg["to_station"]) case "flight": for field in "from_airport", "to_airport": if field in t: @@ -253,7 +236,11 @@ def get_locations(trip: Trip) -> dict[str, StrDict]: terminal = t[field] locations["ferry_terminal"][terminal["name"]] = terminal - locations["station"] = process_station_list(station_list) + for s in station_list: + if s["name"] in locations["station"]: + continue + locations["station"][s["name"]] = s + return locations @@ -389,7 +376,7 @@ def get_trip_routes(trip: Trip, data_dir: str) -> list[StrDict]: for item in trip.conferences if "latitude" in item and "longitude" in item - and item["country"] not in {"gb", "be", "fr"} # not flying to Belgium or France + and item["country"] not in ("gb", "be") # not flying to Belgium ] diff --git a/agenda/types.py b/agenda/types.py index 0b383b1..0bfef4d 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -73,21 +73,20 @@ class Trip: return self.name titles: list[str] = [conf["name"] for conf in self.conferences] + [ event["title"] for event in self.events - ] or self.titles_from_travel() + ] + if not titles: + for travel in self.travel: + if travel["depart"] and utils.as_date(travel["depart"]) != self.start: + place = travel["from"] + if place not in titles: + titles.append(place) + if travel["depart"] and utils.as_date(travel["depart"]) != self.end: + place = travel["to"] + if place not in titles: + titles.append(place) return format_list_with_ampersand(titles) or "[unnamed trip]" - def titles_from_travel(self) -> list[str]: - """Titles from travel.""" - titles = [] - for travel in self.travel: - if not (depart := (travel["depart"] and utils.as_date(travel["depart"]))): - continue - for when, from_or_to in ((self.start, "from"), (self.end, "to")): - if depart != when and travel["from_or_to"] not in titles: - titles.append(travel["from_or_to"]) - return titles - @property def end(self) -> datetime.date | None: """End date for trip.""" diff --git a/validate_yaml.py b/validate_yaml.py index 09ce218..f656ea3 100755 --- a/validate_yaml.py +++ b/validate_yaml.py @@ -56,9 +56,7 @@ def check_flights(airlines: set[str]) -> None: assert "trip" in booking assert all(flight["airline"] in airlines for flight in booking["flights"]) flight_count += len(booking["flights"]) - co2_flight_count += len( - [flight for flight in booking["flights"] if "co2_kg" in flight] - ) + co2_flight_count += len([flight for flight in booking["flights"] if "co2_kg" in flight]) check_currency(booking) if prev_first_depart: @@ -67,10 +65,8 @@ def check_flights(airlines: set[str]) -> None: ), "Bookings are not in chronological order by first flight's departure." prev_first_depart = booking["flights"][0]["depart"] - print( - f"{len(bookings)} flight bookings, {flight_count} flights, " - f"{co2_flight_count} with CO2 numbers" - ) + print(f"{len(bookings)} flight bookings, {flight_count} flights, " + f"{co2_flight_count} with CO2 numbers") def check_trains() -> None: