Update for cancelled and also for from
This commit is contained in:
parent
2bb2704c7d
commit
9a20a23265
@ -1,41 +0,0 @@
|
|||||||
import datetime
|
|
||||||
from typing import List
|
|
||||||
from flask import Flask, render_template, request, make_response
|
|
||||||
import json
|
|
||||||
import requests
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
def get_departure_info(station_name):
|
|
||||||
url = f"https://dbf.finalrewind.org/{station_name}.json?version=3"
|
|
||||||
response = requests.get(url)
|
|
||||||
if response.status_code == 200:
|
|
||||||
departures_data = response.json().get("departures", [])
|
|
||||||
departures = [station_board_leg_to_dict(leg) for leg in departures_data]
|
|
||||||
return departures
|
|
||||||
else:
|
|
||||||
return []
|
|
||||||
|
|
||||||
def station_board_leg_to_dict(leg):
|
|
||||||
return {
|
|
||||||
"name": leg["train"],
|
|
||||||
"direction": leg["destination"],
|
|
||||||
"dateTime": leg["scheduledDeparture"],
|
|
||||||
"delay": leg["delayDeparture"],
|
|
||||||
"platform": leg["scheduledPlatform"],
|
|
||||||
}
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
|
||||||
def index():
|
|
||||||
departures = []
|
|
||||||
station_name = ""
|
|
||||||
|
|
||||||
# Get the station name from the form input
|
|
||||||
if request.method == 'POST':
|
|
||||||
station_name = request.form['station_name']
|
|
||||||
departures = get_departure_info(station_name)
|
|
||||||
|
|
||||||
return render_template('index.html', departures=departures, station_name=station_name)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app.run(host="0.0.0.0", debug=False)
|
|
@ -103,6 +103,9 @@
|
|||||||
color: #FF5000;
|
color: #FF5000;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
.cancelled-row {
|
||||||
|
background-color: #500303;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
function updateDepartures() {
|
function updateDepartures() {
|
||||||
@ -115,28 +118,36 @@
|
|||||||
|
|
||||||
data.departures.forEach(leg => {
|
data.departures.forEach(leg => {
|
||||||
const row = document.createElement('tr');
|
const row = document.createElement('tr');
|
||||||
|
row.className = leg.isCancelled ? 'cancelled-row' : '';
|
||||||
row.innerHTML = `
|
row.innerHTML = `
|
||||||
<td class="centered-cell">${leg.train}<br>(${leg.trainNumber})</td>
|
<td class="centered-cell">${leg.train}<br>(${leg.trainNumber})</td>
|
||||||
|
<td class="centered-cell">${leg.route[0].name}</td>
|
||||||
<td class="centered-cell">${leg.destination}</td>
|
<td class="centered-cell">${leg.destination}</td>
|
||||||
<td class="centered-cell">${leg.via.join(', ')}</td>
|
<td class="centered-cell">${leg.via.join(', ')}</td>
|
||||||
<td class="centered-cell scheduled-arrival-cell"></td>
|
<td class="centered-cell scheduled-arrival-cell"></td>
|
||||||
<td class="centered-cell delay-reasons delay-arrival"></td>
|
<td class="centered-cell delay-arrival"></td>
|
||||||
<td class="centered-cell scheduled-depature-cell"></td>
|
<td class="centered-cell scheduled-depature-cell"></td>
|
||||||
<td class="centered-cell delay-reasons delay-depature"></td>
|
<td class="centered-cell delay-reasons delay-depature"></td>
|
||||||
<td class="centered-cell">${leg.scheduledPlatform}</td>
|
<td class="centered-cell">${leg.scheduledPlatform}</td>
|
||||||
`;
|
`;
|
||||||
const delayArrivalCell = row.querySelector('.delay-arrival');
|
const delayArrivalCell = row.querySelector('.delay-arrival');
|
||||||
if (leg.delayArrival !== null) {
|
if (leg.delayArrival !== null && leg.delayArrival !== 0) {
|
||||||
delayArrivalCell.innerHTML += `<span class="delay-arrival-text">${leg.delayArrival}</span>`;
|
delayArrivalCell.innerHTML += `<span class="delay-arrival-text">${leg.delayArrival}</span>`;
|
||||||
}
|
}
|
||||||
|
else if (leg.delayArrival === 0) {
|
||||||
|
delayArrivalCell.innerHTML += "----------";
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
delayArrivalCell.innerHTML += "----------";
|
delayArrivalCell.innerHTML += "----------";
|
||||||
}
|
}
|
||||||
|
|
||||||
const delayDepartureCell = row.querySelector('.delay-depature');
|
const delayDepartureCell = row.querySelector('.delay-depature');
|
||||||
if (leg.delayDeparture !== null ) {
|
if (leg.delayDeparture !== null && leg.delayDeparture !==0) {
|
||||||
delayDepartureCell.innerHTML += `<span class="delay-depature-text">${leg.delayDeparture}</span>`;
|
delayDepartureCell.innerHTML += `<span class="delay-depature-text">${leg.delayDeparture}</span>`;
|
||||||
}
|
}
|
||||||
|
else if (leg.delayArrival === 0) {
|
||||||
|
delayDepartureCell.innerHTML += "----------";
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
delayDepartureCell.innerHTML += "----------";
|
delayDepartureCell.innerHTML += "----------";
|
||||||
}
|
}
|
||||||
@ -184,46 +195,42 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% if departures %}
|
{% if departures %}
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Richtung / Direction</th>
|
<th>Von / From</th>
|
||||||
<th>Über/ via</th>
|
<th>Richtung / Direction</th>
|
||||||
<th>Geplante Akunftszeit / Planned arrival</th>
|
<th>Über/ via</th>
|
||||||
<th>Verspätung der Ankunft (Minuten) / Arrival delay (minutes)</th>
|
<th>Geplante Ankunftszeit / Planned arrival</th>
|
||||||
<th>Geplante Abfahrtszeit / Planned departure</th>
|
<th>Verspätung der Ankunft (Minuten) / Arrival delay (minutes)</th>
|
||||||
<th>Verspätung der Abfahrt (Minuten) / Depature delay (minutes)<br>Verspätungsgründe / Delay Reasons</th>
|
<th>Geplante Abfahrtszeit / Planned departure</th>
|
||||||
<th>Bahnsteig / Platform</th>
|
<th>Verspätung der Abfahrt (Minuten) / Departure delay (minutes)<br><br>Verspätungsgründe / Delay Reasons</th>
|
||||||
</tr>
|
<th>Bahnsteig / Platform</th>
|
||||||
</thead>
|
</tr>
|
||||||
<tbody>
|
</thead>
|
||||||
{% for leg in departures %}
|
<tbody>
|
||||||
<tr>
|
{% for leg in departures %}
|
||||||
<td class="centered-cell">{{ leg.train }}<br>({{leg.trainNumber}})</td>
|
<tr class="{% if leg.isCancelled %}cancelled-row{% endif %}">
|
||||||
<td class="centered-cell">{{ leg.destination }}</td>
|
<td class="centered-cell">{{ leg.train }}<br>({{ leg.trainNumber }})</td>
|
||||||
<td class="centered-cell">{{ leg.via | join(', ') }}</td>
|
<td class="centered-cell">{{ leg.route[0].name }}</td> <!-- Ursprungsort -->
|
||||||
<td class="centered-cell">{{ leg.scheduledArrival }}</td>
|
<td class="centered-cell">{{ leg.destination }}</td>
|
||||||
<td class="centered-cell delay-reasons delay-arrival"><span class="delay-arrival-text">{{ leg.delayArrival }}</span>
|
<td class="centered-cell">{{ leg.via | join(', ') }}</td>
|
||||||
<table>
|
<td class="centered-cell">{{ leg.scheduledArrival if leg.scheduledArrival else "----------" }}</td>
|
||||||
{% for delay in leg.messages.delay %}
|
<td class="centered-cell delay-arrival"><span class="delay-arrival-text">{{ leg.delayArrival if leg.delayArrival else "----------" }}</span></td>
|
||||||
<tr><td class="centered-cell delay-cell">{{ delay.text }}</td></tr>
|
<td class="centered-cell scheduled-departure-cell">{{ leg.scheduledDeparture if leg.scheduledDeparture else "----------" }}</td>
|
||||||
{% endfor %}
|
<td class="centered-cell delay-reasons delay-departure"><span class="delay-depature-text">{{ leg.delayDeparture if leg.delayDeparture else "----------" }}</span>
|
||||||
</table>
|
<table>
|
||||||
</td>
|
{% for delay in leg.messages.delay %}
|
||||||
<td class="centered-cell scheduled-depature-cell">{{ leg.scheduledDeparture }}</td>
|
<tr><td class="centered-cell delay-cell">{{ delay.text }}</td></tr>
|
||||||
<td class="centered-cell delay-reasons delay-depature"><span class="delay-depature-text">{{ leg.delayDeparture }}</span>
|
{% endfor %}
|
||||||
<table>
|
</table>
|
||||||
{% for delay in leg.messages.delay %}
|
</td>
|
||||||
<tr><td class="centered-cell delay-cell">{{ delay.text }}</td></tr>
|
<td>{{ leg.scheduledPlatform }}</td>
|
||||||
{% endfor %}
|
</tr>
|
||||||
</table>
|
{% endfor %}
|
||||||
</td>
|
</tbody>
|
||||||
<td>{{ leg.scheduledPlatform }}</td>
|
</table>
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
Loading…
Reference in New Issue
Block a user