Update for cancelled and also for from

This commit is contained in:
Rsclub2 2 2023-10-18 14:57:37 +02:00
parent 2bb2704c7d
commit 9a20a23265
2 changed files with 50 additions and 84 deletions

View File

@ -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)

View File

@ -103,6 +103,9 @@
color: #FF5000;
font-weight: bold;
}
.cancelled-row {
background-color: #500303;
}
</style>
<script>
function updateDepartures() {
@ -115,28 +118,36 @@
data.departures.forEach(leg => {
const row = document.createElement('tr');
row.className = leg.isCancelled ? 'cancelled-row' : '';
row.innerHTML = `
<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.via.join(', ')}</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 delay-reasons delay-depature"></td>
<td class="centered-cell">${leg.scheduledPlatform}</td>
`;
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>`;
}
else if (leg.delayArrival === 0) {
delayArrivalCell.innerHTML += "----------";
}
else {
delayArrivalCell.innerHTML += "----------";
}
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>`;
}
else if (leg.delayArrival === 0) {
delayDepartureCell.innerHTML += "----------";
}
else {
delayDepartureCell.innerHTML += "----------";
}
@ -184,46 +195,42 @@
</form>
{% if departures %}
<table>
<thead>
<tr>
<th>Name</th>
<th>Richtung / Direction</th>
<th>Über/ via</th>
<th>Geplante Akunftszeit / Planned arrival</th>
<th>Verspätung der Ankunft (Minuten) / Arrival delay (minutes)</th>
<th>Geplante Abfahrtszeit / Planned departure</th>
<th>Verspätung der Abfahrt (Minuten) / Depature delay (minutes)<br>Verspätungsgründe / Delay Reasons</th>
<th>Bahnsteig / Platform</th>
</tr>
</thead>
<tbody>
{% for leg in departures %}
<tr>
<td class="centered-cell">{{ leg.train }}<br>({{leg.trainNumber}})</td>
<td class="centered-cell">{{ leg.destination }}</td>
<td class="centered-cell">{{ leg.via | join(', ') }}</td>
<td class="centered-cell">{{ leg.scheduledArrival }}</td>
<td class="centered-cell delay-reasons delay-arrival"><span class="delay-arrival-text">{{ leg.delayArrival }}</span>
<table>
{% for delay in leg.messages.delay %}
<tr><td class="centered-cell delay-cell">{{ delay.text }}</td></tr>
{% endfor %}
</table>
</td>
<td class="centered-cell scheduled-depature-cell">{{ leg.scheduledDeparture }}</td>
<td class="centered-cell delay-reasons delay-depature"><span class="delay-depature-text">{{ leg.delayDeparture }}</span>
<table>
{% for delay in leg.messages.delay %}
<tr><td class="centered-cell delay-cell">{{ delay.text }}</td></tr>
{% endfor %}
</table>
</td>
<td>{{ leg.scheduledPlatform }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<table>
<thead>
<tr>
<th>Name</th>
<th>Von / From</th>
<th>Richtung / Direction</th>
<th>Über/ via</th>
<th>Geplante Ankunftszeit / Planned arrival</th>
<th>Verspätung der Ankunft (Minuten) / Arrival delay (minutes)</th>
<th>Geplante Abfahrtszeit / Planned departure</th>
<th>Verspätung der Abfahrt (Minuten) / Departure delay (minutes)<br><br>Verspätungsgründe / Delay Reasons</th>
<th>Bahnsteig / Platform</th>
</tr>
</thead>
<tbody>
{% for leg in departures %}
<tr class="{% if leg.isCancelled %}cancelled-row{% endif %}">
<td class="centered-cell">{{ leg.train }}<br>({{ leg.trainNumber }})</td>
<td class="centered-cell">{{ leg.route[0].name }}</td> <!-- Ursprungsort -->
<td class="centered-cell">{{ leg.destination }}</td>
<td class="centered-cell">{{ leg.via | join(', ') }}</td>
<td class="centered-cell">{{ leg.scheduledArrival if leg.scheduledArrival else "----------" }}</td>
<td class="centered-cell delay-arrival"><span class="delay-arrival-text">{{ leg.delayArrival if leg.delayArrival else "----------" }}</span></td>
<td class="centered-cell scheduled-departure-cell">{{ leg.scheduledDeparture if leg.scheduledDeparture else "----------" }}</td>
<td class="centered-cell delay-reasons delay-departure"><span class="delay-depature-text">{{ leg.delayDeparture if leg.delayDeparture else "----------" }}</span>
<table>
{% for delay in leg.messages.delay %}
<tr><td class="centered-cell delay-cell">{{ delay.text }}</td></tr>
{% endfor %}
</table>
</td>
<td>{{ leg.scheduledPlatform }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
<script>