Link departures to bahn.expert

This commit is contained in:
clerie 2024-07-27 21:57:33 +02:00
parent f29752db77
commit 6e0f2683cb

View File

@ -36,6 +36,7 @@ struct DepartureInfo {
#[derive(Deserialize)]
struct Departure {
departure: Option<DepartureInfo>,
initialDeparture: String,
route: Vec<Stop>,
train: Train,
destination: String,
@ -156,7 +157,7 @@ async fn route_station_overview(
out.push_str(&format!("<li><a href=\"/station/{}/to/{}\">{}</a></li>\n", station, dest_station_id, dest_station.name));
}
out.push_str("<html><body><ul>\n");
out.push_str("</ul></body></html>\n");
return Ok(Html(out));
}
@ -164,7 +165,7 @@ async fn route_station_overview(
async fn route_station_to_dest_station(
State(state): State<AppState>,
Path((station_id, dest_station_id)): Path<(String, String)>
) -> Result<String, (StatusCode, String)> {
) -> Result<Html<String>, (StatusCode, String)> {
if !state.stations.contains_key(&station_id) {
return Err((StatusCode::NOT_FOUND, String::from("Unknown departing station")));
}
@ -201,6 +202,7 @@ async fn route_station_to_dest_station(
let mut out = String::new();
out.push_str("<html><body><ul>\n");
for departure in stationdata.departures {
let departure_info = match departure.departure {
@ -233,10 +235,12 @@ async fn route_station_to_dest_station(
}
if stops_at_destination {
out.push_str(&format!("{}: {} ({} {}) [{}]-> {}\n", departure_info.time, &departure.train.name, &departure.train.r#type, &departure.train.number, departure_info.platform, &departure.destination));
out.push_str(&format!("<li>{}: <a href=\"https://bahn.expert/details/{}%20{}/{}?evaNumberAlongRoute={}\">{} ({} {})</a> [{}]-> {}\n", departure_info.time, &departure.train.r#type, &departure.train.number, &departure.initialDeparture, station_properties.code, &departure.train.name, &departure.train.r#type, &departure.train.number, departure_info.platform, &departure.destination));
}
}
return Ok(out);
out.push_str("</ul></body></html>\n");
return Ok(Html(out));
}