Show past travel
This commit is contained in:
parent
0321d9d283
commit
2fc200c7b2
|
@ -272,7 +272,7 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]:
|
||||||
my_data = config["data"]["personal-data"]
|
my_data = config["data"]["personal-data"]
|
||||||
events += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml"))
|
events += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml"))
|
||||||
events += accommodation.get_events(os.path.join(my_data, "accommodation.yaml"))
|
events += accommodation.get_events(os.path.join(my_data, "accommodation.yaml"))
|
||||||
events += travel.all_events(today, config["data"]["personal-data"])
|
events += travel.all_events(config["data"]["personal-data"])
|
||||||
events += conference.get_list(os.path.join(my_data, "conferences.yaml"))
|
events += conference.get_list(os.path.join(my_data, "conferences.yaml"))
|
||||||
events += backwell_bins + bristol_bins
|
events += backwell_bins + bristol_bins
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
"""Travel."""
|
"""Travel."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import typing
|
|
||||||
from datetime import date
|
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
@ -11,39 +9,27 @@ from .types import Event
|
||||||
Leg = dict[str, str]
|
Leg = dict[str, str]
|
||||||
|
|
||||||
|
|
||||||
def get(
|
def get_flights(data_dir: str) -> list[Event]:
|
||||||
from_date: date,
|
|
||||||
method: str,
|
|
||||||
filepath: str,
|
|
||||||
extra: typing.Callable[[Leg], str] | None = None,
|
|
||||||
) -> list[Event]:
|
|
||||||
"""Get travel events."""
|
"""Get travel events."""
|
||||||
|
filepath = os.path.join(data_dir, "flights.yaml")
|
||||||
def title(item: Leg) -> str:
|
|
||||||
ret = f'{method} from {item["from"]} to {item["to"]}'
|
|
||||||
if extra:
|
|
||||||
ret += f" ({extra(item)})"
|
|
||||||
return ret
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Event(
|
Event(
|
||||||
date=item["depart"],
|
date=item["depart"],
|
||||||
end_date=item["arrive"],
|
end_date=item.get("arrive"),
|
||||||
name="transport",
|
name="transport",
|
||||||
title=title(item),
|
title=f'flight from {item["from"]} to {item["to"]} ({flight_number(item)})',
|
||||||
url=item.get("url"),
|
url=item.get("url"),
|
||||||
)
|
)
|
||||||
for item in yaml.safe_load(open(filepath))
|
for item in yaml.safe_load(open(filepath))
|
||||||
if item["depart"].date() >= from_date
|
if item["depart"].date()
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_trains(from_date: date, filepath: str) -> list[Event]:
|
def get_trains(data_dir: str) -> list[Event]:
|
||||||
"""Get train events."""
|
"""Get train events."""
|
||||||
events: list[Event] = []
|
events: list[Event] = []
|
||||||
|
filepath = os.path.join(data_dir, "trains.yaml")
|
||||||
for item in yaml.safe_load(open(filepath)):
|
for item in yaml.safe_load(open(filepath)):
|
||||||
if item["depart"].date() < from_date:
|
|
||||||
continue
|
|
||||||
events += [
|
events += [
|
||||||
Event(
|
Event(
|
||||||
date=leg["depart"],
|
date=leg["depart"],
|
||||||
|
@ -66,11 +52,6 @@ def flight_number(flight: Leg) -> str:
|
||||||
return airline_code + flight["flight_number"]
|
return airline_code + flight["flight_number"]
|
||||||
|
|
||||||
|
|
||||||
def all_events(from_date: date, data_dir: str) -> list[Event]:
|
def all_events(data_dir: str) -> list[Event]:
|
||||||
"""Get all flights and rail journeys."""
|
"""Get all flights and rail journeys."""
|
||||||
trains = get_trains(from_date, os.path.join(data_dir, "trains.yaml"))
|
return get_trains(data_dir) + get_flights(data_dir)
|
||||||
flights = get(
|
|
||||||
from_date, "flight", os.path.join(data_dir, "flights.yaml"), extra=flight_number
|
|
||||||
)
|
|
||||||
|
|
||||||
return trains + flights
|
|
||||||
|
|
Loading…
Reference in a new issue