Compare commits
3 commits
6333587cc2
...
eaa6369dc9
Author | SHA1 | Date | |
---|---|---|---|
Edward Betts | eaa6369dc9 | ||
Edward Betts | 9f1f64708f | ||
Edward Betts | 1ce82858ae |
|
@ -182,8 +182,11 @@ async def get_data(now: datetime, config: flask.config.Config) -> AgendaData:
|
||||||
plus_365 = now + timedelta(days=365)
|
plus_365 = now + timedelta(days=365)
|
||||||
|
|
||||||
t0 = time()
|
t0 = time()
|
||||||
|
offline_mode = bool(config.get("OFFLINE_MODE"))
|
||||||
result_list = await asyncio.gather(
|
result_list = await asyncio.gather(
|
||||||
time_function("gwr_advance_tickets", gwr.advance_ticket_date, data_dir),
|
time_function(
|
||||||
|
"gwr_advance_tickets", gwr.advance_ticket_date, data_dir, offline_mode
|
||||||
|
),
|
||||||
time_function(
|
time_function(
|
||||||
"backwell_bins",
|
"backwell_bins",
|
||||||
n_somerset_waste_collection_events,
|
n_somerset_waste_collection_events,
|
||||||
|
|
|
@ -48,11 +48,13 @@ def extract_weekday_date(html: str) -> date | None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
async def advance_tickets_page_html(data_dir: str, ttl: int = 60 * 60 * 6) -> str:
|
async def advance_tickets_page_html(
|
||||||
|
data_dir: str, ttl: int = 60 * 60 * 6, force_cache: bool = False
|
||||||
|
) -> str:
|
||||||
"""Get advance-tickets web page HTML with cache."""
|
"""Get advance-tickets web page HTML with cache."""
|
||||||
filename = os.path.join(data_dir, "advance-tickets.html")
|
filename = os.path.join(data_dir, "advance-tickets.html")
|
||||||
mtime = os.path.getmtime(filename) if os.path.exists(filename) else 0
|
mtime = os.path.getmtime(filename) if os.path.exists(filename) else 0
|
||||||
if (time() - mtime) < ttl: # use cache
|
if force_cache or (time() - mtime) < ttl: # use cache
|
||||||
return open(filename).read()
|
return open(filename).read()
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await client.get(url)
|
r = await client.get(url)
|
||||||
|
@ -61,7 +63,7 @@ async def advance_tickets_page_html(data_dir: str, ttl: int = 60 * 60 * 6) -> st
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
async def advance_ticket_date(data_dir: str) -> date | None:
|
async def advance_ticket_date(data_dir: str, force_cache: bool = False) -> date | None:
|
||||||
"""Get GWR advance tickets date with cache."""
|
"""Get GWR advance tickets date with cache."""
|
||||||
html = await advance_tickets_page_html(data_dir)
|
html = await advance_tickets_page_html(data_dir, force_cache=force_cache)
|
||||||
return extract_weekday_date(html)
|
return extract_weekday_date(html)
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
<div class="grid-container">
|
<div class="grid-container">
|
||||||
{{ section("Current", current, "attending") }}
|
{{ section("Current", current, "attending") }}
|
||||||
{{ section("Future", future, "going") }}
|
{{ section("Future", future, "going") }}
|
||||||
{{ section("Past", past|reverse, "went") }}
|
{{ section("Past", past|reverse|list, "went") }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,138 +0,0 @@
|
||||||
{% extends "base.html" %}
|
|
||||||
|
|
||||||
{% from "macros.html" import trip_link, display_date_no_year, display_date, conference_row, accommodation_row, flight_row, train_row, ferry_row with context %}
|
|
||||||
|
|
||||||
{% set row = { "flight": flight_row, "train": train_row, "ferry": ferry_row } %}
|
|
||||||
|
|
||||||
{% block title %}Trips - Edward Betts{% endblock %}
|
|
||||||
|
|
||||||
{% block style %}
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="{{ url_for("static", filename="leaflet/leaflet.css") }}">
|
|
||||||
|
|
||||||
{% set conference_column_count = 8 %}
|
|
||||||
{% set accommodation_column_count = 8 %}
|
|
||||||
{% set travel_column_count = 10 %}
|
|
||||||
<style>
|
|
||||||
.conferences {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat({{ conference_column_count }}, auto); /* 7 columns for each piece of information */
|
|
||||||
gap: 10px;
|
|
||||||
justify-content: start;
|
|
||||||
}
|
|
||||||
|
|
||||||
.accommodation {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat({{ accommodation_column_count }}, auto);
|
|
||||||
gap: 10px;
|
|
||||||
justify-content: start;
|
|
||||||
}
|
|
||||||
|
|
||||||
.travel {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat({{ travel_column_count }}, auto);
|
|
||||||
gap: 10px;
|
|
||||||
justify-content: start;
|
|
||||||
}
|
|
||||||
|
|
||||||
.grid-item {
|
|
||||||
/* Additional styling for grid items can go here */
|
|
||||||
}
|
|
||||||
|
|
||||||
.map {
|
|
||||||
height: 80vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</style>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% macro section(heading, item_list, badge) %}
|
|
||||||
{% if item_list %}
|
|
||||||
{% set items = item_list | list %}
|
|
||||||
<div class="heading"><h2>{{ heading }}</h2></div>
|
|
||||||
<p>{{ items | count }} trips</p>
|
|
||||||
{% for trip in items %}
|
|
||||||
{% set total_distance = trip.total_distance() %}
|
|
||||||
{% set end = trip.end %}
|
|
||||||
<div class="border border-2 rounded mb-2 p-2">
|
|
||||||
<h3>
|
|
||||||
{{ trip_link(trip) }}
|
|
||||||
<small class="text-muted">({{ display_date(trip.start) }})</small></h3>
|
|
||||||
<div>Countries: {{ trip.countries_str }}</div>
|
|
||||||
{% if end %}
|
|
||||||
<div>Dates: {{ display_date_no_year(trip.start) }} to {{ display_date_no_year(end) }}</div>
|
|
||||||
{% else %}
|
|
||||||
<div>Start: {{ display_date_no_year(trip.start) }} (end date missing)</div>
|
|
||||||
{% endif %}
|
|
||||||
{% if total_distance %}
|
|
||||||
<div>Total distance:
|
|
||||||
{{ "{:,.0f} km / {:,.0f} miles".format(total_distance, total_distance / 1.60934) }}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
<div class="conferences">
|
|
||||||
{% for conf in trip.conferences %}
|
|
||||||
{{ conference_row(conf, "going") }}
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="accommodation">
|
|
||||||
{% for conf in trip.accommodation %}
|
|
||||||
{{ accommodation_row(conf, "going") }}
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="travel">
|
|
||||||
{% for item in trip.travel %}
|
|
||||||
{{ row[item.type](item) }}
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
{% endmacro %}
|
|
||||||
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="p-2">
|
|
||||||
|
|
||||||
|
|
||||||
<h1>Trips</h1>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-1">
|
|
||||||
</div>
|
|
||||||
<div class="col-11">
|
|
||||||
<div id="future-map" class="map"></div>
|
|
||||||
</div>
|
|
||||||
{{ section("Current", current, "attending") }}
|
|
||||||
{{ section("Future", future, "going") }}
|
|
||||||
<div class="col-1">
|
|
||||||
</div>
|
|
||||||
<div class="col-11">
|
|
||||||
<div id="past-map" class="map"></div>
|
|
||||||
</div>
|
|
||||||
{{ section("Past", past|reverse, "went") }}
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
|
|
||||||
<script src="{{ url_for("static", filename="leaflet/leaflet.js") }}"></script>
|
|
||||||
|
|
||||||
<script src="{{ url_for("static", filename="leaflet-geodesic/leaflet.geodesic.umd.min.js") }}"></script>
|
|
||||||
<script src="{{ url_for("static", filename="js/map.js") }}"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
var future_coordinates = {{ future_coordinates | tojson }};
|
|
||||||
var future_routes = {{ future_routes | tojson }};
|
|
||||||
|
|
||||||
build_map("future-map", future_coordinates, future_routes);
|
|
||||||
|
|
||||||
var past_coordinates = {{ past_coordinates | tojson }};
|
|
||||||
var past_routes = {{ past_routes | tojson }};
|
|
||||||
|
|
||||||
build_map("past-map", past_coordinates, past_routes);
|
|
||||||
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
35
web_view.py
35
web_view.py
|
@ -379,41 +379,6 @@ def get_trip_list(
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@app.route("/trip/old")
|
|
||||||
def trip_old_list() -> str:
|
|
||||||
"""Page showing a list of trips."""
|
|
||||||
route_distances = agenda.travel.load_route_distances(app.config["DATA_DIR"])
|
|
||||||
trip_list = get_trip_list(route_distances)
|
|
||||||
today = date.today()
|
|
||||||
|
|
||||||
current = [
|
|
||||||
item
|
|
||||||
for item in trip_list
|
|
||||||
if item.start <= today and (item.end or item.start) >= today
|
|
||||||
]
|
|
||||||
|
|
||||||
past = [item for item in trip_list if (item.end or item.start) < today]
|
|
||||||
future = [item for item in trip_list if item.start > today]
|
|
||||||
|
|
||||||
future_coordinates, future_routes = agenda.trip.get_coordinates_and_routes(future)
|
|
||||||
past_coordinates, past_routes = agenda.trip.get_coordinates_and_routes(past)
|
|
||||||
|
|
||||||
return flask.render_template(
|
|
||||||
"trip_list.html",
|
|
||||||
current=current,
|
|
||||||
past=past,
|
|
||||||
future=future,
|
|
||||||
future_coordinates=future_coordinates,
|
|
||||||
future_routes=future_routes,
|
|
||||||
past_coordinates=past_coordinates,
|
|
||||||
past_routes=past_routes,
|
|
||||||
today=today,
|
|
||||||
get_country=agenda.get_country,
|
|
||||||
format_list_with_ampersand=format_list_with_ampersand,
|
|
||||||
fx_rate=agenda.fx.get_rates(app.config),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/trip")
|
@app.route("/trip")
|
||||||
def trip_list() -> werkzeug.Response:
|
def trip_list() -> werkzeug.Response:
|
||||||
"""Trip list to redirect to future trip list."""
|
"""Trip list to redirect to future trip list."""
|
||||||
|
|
Loading…
Reference in a new issue