Add more detail to web page
This commit is contained in:
parent
036c0cfbd8
commit
348162169f
|
@ -2,7 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<title>Eurotunnel prices</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
|
||||
</head>
|
||||
|
||||
|
@ -11,12 +11,14 @@
|
|||
<body>
|
||||
<div class="container mt-3">
|
||||
|
||||
<p>All Flexi Long Stay tickets are £269</p>
|
||||
<p>Pay an extra £40 to make a price return refundable.</p>
|
||||
<h1>Eurotunnel prices</h1>
|
||||
|
||||
<p>All Flexi Long Stay tickets are £269. Pay an extra £40 to make a return ticket refundable.</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
|
||||
<h3>Out: {{ out_date.strftime("%a, %-d %b %Y") }}</h3>
|
||||
<p>Updated: {{ out_ts.strftime("%a, %-d %b %Y at %H:%M") }}</p>
|
||||
<table class="table table-sm w-auto">
|
||||
<tr>
|
||||
|
@ -36,6 +38,7 @@
|
|||
|
||||
<div class="col">
|
||||
|
||||
<h3>Return: {{ back_date.strftime("%a, %-d %b %Y") }}</h3>
|
||||
<p>Updated: {{ back_ts.strftime("%a, %-d %b %Y at %H:%M") }}</p>
|
||||
<table class="table table-sm w-auto">
|
||||
<tr>
|
||||
|
|
20
web_view.py
20
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,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue