Link departures to bahn.expert
This commit is contained in:
parent
f29752db77
commit
6e0f2683cb
12
src/main.rs
12
src/main.rs
@ -36,6 +36,7 @@ struct DepartureInfo {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Departure {
|
struct Departure {
|
||||||
departure: Option<DepartureInfo>,
|
departure: Option<DepartureInfo>,
|
||||||
|
initialDeparture: String,
|
||||||
route: Vec<Stop>,
|
route: Vec<Stop>,
|
||||||
train: Train,
|
train: Train,
|
||||||
destination: String,
|
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(&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));
|
return Ok(Html(out));
|
||||||
}
|
}
|
||||||
@ -164,7 +165,7 @@ async fn route_station_overview(
|
|||||||
async fn route_station_to_dest_station(
|
async fn route_station_to_dest_station(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((station_id, dest_station_id)): Path<(String, String)>
|
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) {
|
if !state.stations.contains_key(&station_id) {
|
||||||
return Err((StatusCode::NOT_FOUND, String::from("Unknown departing station")));
|
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();
|
let mut out = String::new();
|
||||||
|
|
||||||
|
out.push_str("<html><body><ul>\n");
|
||||||
|
|
||||||
for departure in stationdata.departures {
|
for departure in stationdata.departures {
|
||||||
let departure_info = match departure.departure {
|
let departure_info = match departure.departure {
|
||||||
@ -233,10 +235,12 @@ async fn route_station_to_dest_station(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if stops_at_destination {
|
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));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user