diff --git a/templates/index.html b/templates/index.html
index 5304790..e1f4ef5 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -2,7 +2,7 @@
-
+ Eurotunnel prices
@@ -11,12 +11,14 @@
-
All Flexi Long Stay tickets are £269
-
Pay an extra £40 to make a price return refundable.
+
Eurotunnel prices
+
+
All Flexi Long Stay tickets are £269. Pay an extra £40 to make a return ticket refundable.
+
Out: {{ out_date.strftime("%a, %-d %b %Y") }}
Updated: {{ out_ts.strftime("%a, %-d %b %Y at %H:%M") }}
@@ -36,6 +38,7 @@
+
Return: {{ back_date.strftime("%a, %-d %b %Y") }}
Updated: {{ back_ts.strftime("%a, %-d %b %Y at %H:%M") }}
diff --git a/web_view.py b/web_view.py
index 135eab8..01c055c 100755
--- a/web_view.py
+++ b/web_view.py
@@ -2,7 +2,7 @@
import os
from dataclasses import dataclass
-from datetime import UTC, datetime
+from datetime import UTC, datetime, date
from decimal import Decimal
import flask
@@ -12,7 +12,7 @@ import pytz
app = flask.Flask(__name__)
app.debug = True
-data_loc = os.path.expanduser("~/lib/data/eurotunnel")
+data_loc = os.path.expanduser("~edward/lib/data/eurotunnel")
def get_filename(direction: str) -> tuple[datetime, str]:
@@ -35,7 +35,7 @@ class Train:
price: Decimal | None = None
-def get_tickets(filename: str) -> list[Train]:
+def get_tickets(filename: str) -> tuple[date, list[Train]]:
"""Get trains and prices."""
tree = lxml.html.parse(filename)
root = tree.getroot()
@@ -43,6 +43,12 @@ def get_tickets(filename: str) -> list[Train]:
trains = []
by_time = {}
+ day_div = root.find(".//div[@class='col-md-1 als-item selected']")
+ assert day_div
+ day_id = day_div.get("data-id")
+ assert day_id
+ d = date.fromisoformat(day_id[1:])
+
for mission in root.findall(".//div[@data-mission]"):
dep_text = mission.findtext(".//b")
assert dep_text
@@ -69,25 +75,27 @@ def get_tickets(filename: str) -> list[Train]:
by_time[mission_time].price = price
- return trains
+ return (d, trains)
@app.route("/")
def index() -> str:
"""Index."""
out_ts, out_filename = get_filename("outbound")
- out = get_tickets(out_filename)
+ out_date, out = get_tickets(out_filename)
out = [t for t in out if t.dep > "0800" and "0700" < t.arr < "2200"]
back_ts, back_filename = get_filename("return")
- back = get_tickets(back_filename)
+ back_date, back = get_tickets(back_filename)
back = [t for t in back if t.dep > "1100" and "0700" < t.arr < "2200"]
return flask.render_template(
"index.html",
out_ts=out_ts,
+ out_date=out_date,
out=out,
back_ts=back_ts,
+ back_date=back_date,
back=back,
)