Handle rail journeys without specific time
This commit is contained in:
parent
1ed6c50ad8
commit
f1338e5970
|
@ -1,6 +1,6 @@
|
||||||
import operator
|
|
||||||
import os
|
import os
|
||||||
from datetime import date
|
from datetime import date, datetime, time
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -41,6 +41,13 @@ def load_trains() -> list[StrDict]:
|
||||||
return trains
|
return trains
|
||||||
|
|
||||||
|
|
||||||
|
def depart_datetime(item: StrDict) -> datetime:
|
||||||
|
depart = item["depart"]
|
||||||
|
if isinstance(depart, datetime):
|
||||||
|
return depart
|
||||||
|
return datetime.combine(depart, time.min).replace(tzinfo=ZoneInfo("UTC"))
|
||||||
|
|
||||||
|
|
||||||
def load_flights() -> list[StrDict]:
|
def load_flights() -> list[StrDict]:
|
||||||
"""Load flights."""
|
"""Load flights."""
|
||||||
data_dir = flask.current_app.config["PERSONAL_DATA"]
|
data_dir = flask.current_app.config["PERSONAL_DATA"]
|
||||||
|
@ -63,9 +70,7 @@ def build_trip_list() -> list[Trip]:
|
||||||
|
|
||||||
data_dir = flask.current_app.config["PERSONAL_DATA"]
|
data_dir = flask.current_app.config["PERSONAL_DATA"]
|
||||||
|
|
||||||
travel_items = sorted(
|
travel_items = sorted(load_flights() + load_trains(), key=depart_datetime)
|
||||||
load_flights() + load_trains(), key=operator.itemgetter("depart")
|
|
||||||
)
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"travel": travel_items,
|
"travel": travel_items,
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Trip:
|
||||||
)
|
)
|
||||||
assert isinstance(max_conference_end, datetime.date)
|
assert isinstance(max_conference_end, datetime.date)
|
||||||
|
|
||||||
arrive = [item["arrive"].date() for item in self.travel if "arrive" in item]
|
arrive = [as_date(item["arrive"]) for item in self.travel if "arrive" in item]
|
||||||
travel_end = max(arrive) if arrive else datetime.date.min
|
travel_end = max(arrive) if arrive else datetime.date.min
|
||||||
assert isinstance(travel_end, datetime.date)
|
assert isinstance(travel_end, datetime.date)
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@
|
||||||
<div class="grid-item">
|
<div class="grid-item">
|
||||||
{% if item.arrive %}
|
{% if item.arrive %}
|
||||||
{{ item.arrive.strftime("%H:%M") }}
|
{{ item.arrive.strftime("%H:%M") }}
|
||||||
{% if item.arrive.date() != item.depart.date() %}+1 day{% endif %}
|
{% if item.depart != item.arrive and item.arrive.date() != item.depart.date() %}+1 day{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="grid-item">{{ ((item.arrive - item.depart).total_seconds() // 60) | int }} mins</div>
|
<div class="grid-item">{{ ((item.arrive - item.depart).total_seconds() // 60) | int }} mins</div>
|
||||||
|
|
Loading…
Reference in a new issue