Compare commits
No commits in common. "4bde0d8524e9c6d6354f803b69f5674debc0517e" and "f7022c992de896a5812328e359423285a4ed8fc5" have entirely different histories.
4bde0d8524
...
f7022c992d
|
@ -23,17 +23,7 @@ from dateutil.relativedelta import FR, relativedelta
|
||||||
|
|
||||||
from agenda import thespacedevs
|
from agenda import thespacedevs
|
||||||
|
|
||||||
from . import (
|
from . import birthday, calendar, economist, fx, gwr, markets, sun, waste_schedule
|
||||||
birthday,
|
|
||||||
calendar,
|
|
||||||
economist,
|
|
||||||
fx,
|
|
||||||
gwr,
|
|
||||||
markets,
|
|
||||||
sun,
|
|
||||||
travel,
|
|
||||||
waste_schedule,
|
|
||||||
)
|
|
||||||
from .types import Event
|
from .types import Event
|
||||||
|
|
||||||
warnings.simplefilter(action="ignore", category=FutureWarning)
|
warnings.simplefilter(action="ignore", category=FutureWarning)
|
||||||
|
@ -288,17 +278,77 @@ def get_accommodation(from_date: date, filepath: str) -> list[Event]:
|
||||||
)
|
)
|
||||||
from_date = item["from"]
|
from_date = item["from"]
|
||||||
to_date = item["to"]
|
to_date = item["to"]
|
||||||
|
# nights = (to_date.date() - from_date.date()).days
|
||||||
|
# night_str = f"{nights} nights" if nights != 1 else "1 night"
|
||||||
e = Event(
|
e = Event(
|
||||||
date=from_date,
|
date=from_date,
|
||||||
end_date=to_date,
|
end_date=to_date,
|
||||||
name="accommodation",
|
name="accommodation",
|
||||||
|
# title=f"check-in {title} ({night_str})",
|
||||||
title=title,
|
title=title,
|
||||||
url=item.get("url"),
|
url=item.get("url"),
|
||||||
)
|
)
|
||||||
events.append(e)
|
events.append(e)
|
||||||
|
# checkout = Event(
|
||||||
|
# date=to_date,
|
||||||
|
# name="accommodation",
|
||||||
|
# title="check-out " + title,
|
||||||
|
# url=item.get("url"),
|
||||||
|
# )
|
||||||
|
# events += [checkin, checkout]
|
||||||
return events
|
return events
|
||||||
|
|
||||||
|
|
||||||
|
Leg = dict[str, str]
|
||||||
|
|
||||||
|
|
||||||
|
def get_travel(
|
||||||
|
from_date: date,
|
||||||
|
method: str,
|
||||||
|
filepath: str,
|
||||||
|
extra: typing.Callable[[Leg], str] | None = None,
|
||||||
|
) -> list[Event]:
|
||||||
|
"""Get travel events."""
|
||||||
|
|
||||||
|
def title(item: Leg) -> str:
|
||||||
|
ret = f'{method} from {item["from"]} to {item["to"]}'
|
||||||
|
if extra:
|
||||||
|
ret += f" ({extra(item)})"
|
||||||
|
return ret
|
||||||
|
|
||||||
|
return [
|
||||||
|
Event(
|
||||||
|
date=item["depart"],
|
||||||
|
end_date=item["arrive"],
|
||||||
|
name="transport",
|
||||||
|
title=title(item),
|
||||||
|
url=item.get("url"),
|
||||||
|
)
|
||||||
|
for item in yaml.safe_load(open(filepath))
|
||||||
|
if item["depart"].date() >= from_date
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def flight_number(flight: Leg) -> str:
|
||||||
|
"""Flight number."""
|
||||||
|
airline_code = flight["airline"]
|
||||||
|
# make sure this is the airline code, not the airline name
|
||||||
|
assert " " not in airline_code and not any(c.islower() for c in airline_code)
|
||||||
|
|
||||||
|
return airline_code + flight["flight_number"]
|
||||||
|
|
||||||
|
|
||||||
|
def get_all_travel_events(from_date: date) -> list[Event]:
|
||||||
|
"""Get all flights and rail journeys."""
|
||||||
|
data_dir = config["data"]["personal-data"]
|
||||||
|
trains = get_travel(from_date, "train", os.path.join(data_dir, "trains.yaml"))
|
||||||
|
flights = get_travel(
|
||||||
|
from_date, "flight", os.path.join(data_dir, "flights.yaml"), extra=flight_number
|
||||||
|
)
|
||||||
|
|
||||||
|
return trains + flights
|
||||||
|
|
||||||
|
|
||||||
def waste_collection_events() -> list[Event]:
|
def waste_collection_events() -> list[Event]:
|
||||||
"""Waste colllection events."""
|
"""Waste colllection events."""
|
||||||
postcode = "BS48 3HG"
|
postcode = "BS48 3HG"
|
||||||
|
@ -370,7 +420,7 @@ 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 += get_accommodation(today, os.path.join(my_data, "accommodation.yaml"))
|
events += get_accommodation(today, os.path.join(my_data, "accommodation.yaml"))
|
||||||
events += travel.all_events(today, config["data"]["personal-data"])
|
events += get_all_travel_events(today)
|
||||||
events += get_conferences(os.path.join(my_data, "conferences.yaml"))
|
events += get_conferences(os.path.join(my_data, "conferences.yaml"))
|
||||||
events += waste_collection_events() + bristol_waste_collection_events(today)
|
events += waste_collection_events() + bristol_waste_collection_events(today)
|
||||||
|
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
"""Travel."""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import typing
|
|
||||||
from datetime import date
|
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
from .types import Event
|
|
||||||
|
|
||||||
Leg = dict[str, str]
|
|
||||||
|
|
||||||
|
|
||||||
def get(
|
|
||||||
from_date: date,
|
|
||||||
method: str,
|
|
||||||
filepath: str,
|
|
||||||
extra: typing.Callable[[Leg], str] | None = None,
|
|
||||||
) -> list[Event]:
|
|
||||||
"""Get travel events."""
|
|
||||||
|
|
||||||
def title(item: Leg) -> str:
|
|
||||||
ret = f'{method} from {item["from"]} to {item["to"]}'
|
|
||||||
if extra:
|
|
||||||
ret += f" ({extra(item)})"
|
|
||||||
return ret
|
|
||||||
|
|
||||||
return [
|
|
||||||
Event(
|
|
||||||
date=item["depart"],
|
|
||||||
end_date=item["arrive"],
|
|
||||||
name="transport",
|
|
||||||
title=title(item),
|
|
||||||
url=item.get("url"),
|
|
||||||
)
|
|
||||||
for item in yaml.safe_load(open(filepath))
|
|
||||||
if item["depart"].date() >= from_date
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def flight_number(flight: Leg) -> str:
|
|
||||||
"""Flight number."""
|
|
||||||
airline_code = flight["airline"]
|
|
||||||
# make sure this is the airline code, not the airline name
|
|
||||||
assert " " not in airline_code and not any(c.islower() for c in airline_code)
|
|
||||||
|
|
||||||
return airline_code + flight["flight_number"]
|
|
||||||
|
|
||||||
|
|
||||||
def all_events(from_date: date, data_dir: str) -> list[Event]:
|
|
||||||
"""Get all flights and rail journeys."""
|
|
||||||
trains = get(from_date, "train", os.path.join(data_dir, "trains.yaml"))
|
|
||||||
flights = get(
|
|
||||||
from_date, "flight", os.path.join(data_dir, "flights.yaml"), extra=flight_number
|
|
||||||
)
|
|
||||||
|
|
||||||
return trains + flights
|
|
Loading…
Reference in a new issue