New screens/departures.py using the free, unofficial db-vendo-client REST
API (v6.db.transport.rest) -- no key needed, same "no API key" philosophy
as Weather's Open-Meteo integration. Community-run infra though, not
official DB, and it was actually down (503, then timing out entirely) for
the whole time I was building this -- couldn't live-verify against real
data the way Open-Meteo was earlier, so I built the parsing against the
project's documented example response and stress-tested render() with
mocked requests.get() covering on-time/delayed/cancelled/missing-platform/
very-long-direction cases instead. check() fails soft (logs a warning,
returns None) on any request error, matching the "service might be down"
reality of this API -- the screen shows a plain "not available" message
rather than erroring out.
Settings: station name (resolved to a station ID via /locations, same
pattern as Weather's city->coordinates geocoding), how many departures to
show (3/5/8), and its own configurable update interval via the
get_poll_interval() mechanism built for Weather (defaults to 2 min --
departure boards go stale much faster than weather does).
Caught two real layout bugs while stress-testing render() before shipping:
line names ("ICE 1234") and delayed/cancelled time text ("Fällt aus") were
both wider than the columns I'd budgeted for them, with the second one
overlapping the direction text when right-aligned past its column's own
left edge. Fixed by measuring actual worst-case widths at the chosen font
size instead of guessing, and truncating every field to its column as a
defensive backstop regardless.
48 lines
1.8 KiB
HTML
48 lines
1.8 KiB
HTML
{% extends "base.html" %}
|
|
{% block content %}
|
|
<h1>Departures</h1>
|
|
|
|
{% if error %}
|
|
<div class="toast error">{{ error }}</div>
|
|
{% endif %}
|
|
|
|
<p class="hint" style="margin: -0.5rem 0 1.25rem;">
|
|
Uses the free, unofficial db-vendo-client API (v6.db.transport.rest) --
|
|
no key needed, but it's a community-run service, not official Deutsche
|
|
Bahn infrastructure. Expect occasional downtime; the screen shows a plain
|
|
"not available" message rather than breaking when that happens.
|
|
</p>
|
|
|
|
<form method="post">
|
|
<div class="card">
|
|
<div class="section-label">Station</div>
|
|
<div class="field">
|
|
<label for="station">Station name</label>
|
|
<input type="text" id="station" name="station" placeholder="e.g. Berlin Hauptbahnhof">
|
|
{% if settings.station_label %}
|
|
<p class="hint">Currently: {{ settings.station_label }}</p>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="section-label">Display</div>
|
|
<div class="field">
|
|
<label for="results">Departures to show</label>
|
|
<select id="results" name="results">
|
|
<option value="3" {{ "selected" if settings.results == 3 }}>3</option>
|
|
<option value="5" {{ "selected" if settings.results == 5 or not settings.results }}>5</option>
|
|
<option value="8" {{ "selected" if settings.results == 8 }}>8</option>
|
|
</select>
|
|
</div>
|
|
<div class="field">
|
|
<label for="update_minutes">Update every (minutes)</label>
|
|
<input type="number" id="update_minutes" name="update_minutes" min="1" value="{{ settings.update_minutes or 2 }}">
|
|
<p class="hint">Departure boards change often, so this defaults much shorter than Weather's -- but same rule applies: the panel only actually redraws when something in the list changed.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit">Save</button>
|
|
</form>
|
|
{% endblock %}
|