Add more detail to web page
This commit is contained in:
parent
036c0cfbd8
commit
348162169f
|
@ -2,7 +2,7 @@
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<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">
|
<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>
|
</head>
|
||||||
|
|
||||||
|
@ -11,12 +11,14 @@
|
||||||
<body>
|
<body>
|
||||||
<div class="container mt-3">
|
<div class="container mt-3">
|
||||||
|
|
||||||
<p>All Flexi Long Stay tickets are £269</p>
|
<h1>Eurotunnel prices</h1>
|
||||||
<p>Pay an extra £40 to make a price return refundable.</p>
|
|
||||||
|
<p>All Flexi Long Stay tickets are £269. Pay an extra £40 to make a return ticket refundable.</p>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<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>
|
<p>Updated: {{ out_ts.strftime("%a, %-d %b %Y at %H:%M") }}</p>
|
||||||
<table class="table table-sm w-auto">
|
<table class="table table-sm w-auto">
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -36,6 +38,7 @@
|
||||||
|
|
||||||
<div class="col">
|
<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>
|
<p>Updated: {{ back_ts.strftime("%a, %-d %b %Y at %H:%M") }}</p>
|
||||||
<table class="table table-sm w-auto">
|
<table class="table table-sm w-auto">
|
||||||
<tr>
|
<tr>
|
||||||
|
|
20
web_view.py
20
web_view.py
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime, date
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
@ -12,7 +12,7 @@ import pytz
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
app.debug = True
|
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]:
|
def get_filename(direction: str) -> tuple[datetime, str]:
|
||||||
|
@ -35,7 +35,7 @@ class Train:
|
||||||
price: Decimal | None = None
|
price: Decimal | None = None
|
||||||
|
|
||||||
|
|
||||||
def get_tickets(filename: str) -> list[Train]:
|
def get_tickets(filename: str) -> tuple[date, list[Train]]:
|
||||||
"""Get trains and prices."""
|
"""Get trains and prices."""
|
||||||
tree = lxml.html.parse(filename)
|
tree = lxml.html.parse(filename)
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
@ -43,6 +43,12 @@ def get_tickets(filename: str) -> list[Train]:
|
||||||
trains = []
|
trains = []
|
||||||
by_time = {}
|
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]"):
|
for mission in root.findall(".//div[@data-mission]"):
|
||||||
dep_text = mission.findtext(".//b")
|
dep_text = mission.findtext(".//b")
|
||||||
assert dep_text
|
assert dep_text
|
||||||
|
@ -69,25 +75,27 @@ def get_tickets(filename: str) -> list[Train]:
|
||||||
|
|
||||||
by_time[mission_time].price = price
|
by_time[mission_time].price = price
|
||||||
|
|
||||||
return trains
|
return (d, trains)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index() -> str:
|
def index() -> str:
|
||||||
"""Index."""
|
"""Index."""
|
||||||
out_ts, out_filename = get_filename("outbound")
|
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"]
|
out = [t for t in out if t.dep > "0800" and "0700" < t.arr < "2200"]
|
||||||
|
|
||||||
back_ts, back_filename = get_filename("return")
|
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"]
|
back = [t for t in back if t.dep > "1100" and "0700" < t.arr < "2200"]
|
||||||
|
|
||||||
return flask.render_template(
|
return flask.render_template(
|
||||||
"index.html",
|
"index.html",
|
||||||
out_ts=out_ts,
|
out_ts=out_ts,
|
||||||
|
out_date=out_date,
|
||||||
out=out,
|
out=out,
|
||||||
back_ts=back_ts,
|
back_ts=back_ts,
|
||||||
|
back_date=back_date,
|
||||||
back=back,
|
back=back,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue