Compare commits
7 Commits
f9f9669446
...
f57b2452f9
Author | SHA1 | Date | |
---|---|---|---|
f57b2452f9 | |||
0b793484e7 | |||
864c94ea94 | |||
afee3b0c6f | |||
6524b08cf4 | |||
83b28fb580 | |||
0dbe7ec080 |
45
src/main.rs
45
src/main.rs
@ -20,7 +20,6 @@ struct Train {
|
||||
number: String,
|
||||
//line: String,
|
||||
r#type: String,
|
||||
admin: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@ -37,11 +36,11 @@ struct DepartureInfo {
|
||||
#[derive(Deserialize)]
|
||||
struct Departure {
|
||||
departure: Option<DepartureInfo>,
|
||||
initialDeparture: String,
|
||||
#[serde(rename = "initialDeparture")]
|
||||
initial_departure: String,
|
||||
route: Vec<Stop>,
|
||||
train: Train,
|
||||
destination: String,
|
||||
initialStopPlace: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@ -135,7 +134,9 @@ async fn route_index(
|
||||
) -> Result<Html<String>, String> {
|
||||
let mut out = String::new();
|
||||
|
||||
out.push_str("<html><body>\n");
|
||||
out.push_str("<html>\n");
|
||||
out.push_str("<header><title>Nur Ausstieg</title></header>\n");
|
||||
out.push_str("<body>\n");
|
||||
out.push_str("<h1>Nur ausstieg</h1>\n");
|
||||
out.push_str("<p>Es gibt Züge die innerhalb Berlins fahren, aber nicht im Fahrplan Routing der DB auftauchen, weil sie entweder in Berlin enden oder in Berlin beginnen.<br>\n");
|
||||
out.push_str("Diese Seite zeigt für verschiene Stationen genau diese Züge an.</p>\n");
|
||||
@ -145,7 +146,9 @@ async fn route_index(
|
||||
out.push_str(&format!("<li><a href=\"/station/{}\">{}</a></li>\n", id, station.name));
|
||||
}
|
||||
|
||||
out.push_str("</ul></body></html>\n");
|
||||
out.push_str("</ul>\n");
|
||||
out.push_str("<p><small><a href=\"/\">Nur Ausstieg</a> | <a href=\"https://git.clerie.de/clerie/nurausstieg\">Source Code</a></small></p>\n");
|
||||
out.push_str("</body></html>\n");
|
||||
|
||||
return Ok(Html(out));
|
||||
}
|
||||
@ -165,15 +168,23 @@ async fn route_station_overview(
|
||||
|
||||
let mut out = String::new();
|
||||
|
||||
out.push_str("<html><body>\n");
|
||||
out.push_str("<html>\n");
|
||||
out.push_str(&format!("<header><title>Ziele für {} | Nur Ausstieg</title></header>\n", station_properties.name));
|
||||
out.push_str("<body>\n");
|
||||
out.push_str(&format!("<h1>Ziele für {}</h1>\n", station_properties.name));
|
||||
out.push_str("<ul>\n");
|
||||
|
||||
for (dest_station_id, dest_station) in state.stations.into_iter() {
|
||||
if dest_station_id == station_id {
|
||||
continue;
|
||||
}
|
||||
|
||||
out.push_str(&format!("<li><a href=\"/station/{}/to/{}\">{}</a></li>\n", station_id, dest_station_id, dest_station.name));
|
||||
}
|
||||
|
||||
out.push_str("</ul></body></html>\n");
|
||||
out.push_str("</ul>\n");
|
||||
out.push_str("<p><small><a href=\"/\">Nur Ausstieg</a> | <a href=\"https://git.clerie.de/clerie/nurausstieg\">Source Code</a></small></p>\n");
|
||||
out.push_str("</body></html>\n");
|
||||
|
||||
return Ok(Html(out));
|
||||
}
|
||||
@ -191,6 +202,10 @@ async fn route_station_to_dest_station(
|
||||
return Err((StatusCode::NOT_FOUND, String::from("Unknown destination station")));
|
||||
}
|
||||
|
||||
if dest_station_id == station_id {
|
||||
return Err((StatusCode::NOT_FOUND, String::from("Cannot route to departing station as destination")));
|
||||
}
|
||||
|
||||
let station_properties = match state.stations.get(&station_id) {
|
||||
Some(v) => v,
|
||||
None => return Err((StatusCode::INTERNAL_SERVER_ERROR, String::from("Station properties for departing station missing"))),
|
||||
@ -220,8 +235,10 @@ async fn route_station_to_dest_station(
|
||||
|
||||
let mut out = String::new();
|
||||
|
||||
out.push_str("<html><body>\n");
|
||||
out.push_str(&format!("<h1>Abfahren für {} nach {}</h1>\n", station_properties.name, dest_station_properties.name));
|
||||
out.push_str("<html>\n");
|
||||
out.push_str(&format!("<header><title>Abfahrten für {} nach {} | Nur Ausstieg</title></header>\n", station_properties.name, dest_station_properties.name));
|
||||
out.push_str("<body>\n");
|
||||
out.push_str(&format!("<h1>Abfahrten für {} nach {}</h1>\n", station_properties.name, dest_station_properties.name));
|
||||
|
||||
let display_all_departures = match query.all {
|
||||
Some(_) => true,
|
||||
@ -251,10 +268,8 @@ async fn route_station_to_dest_station(
|
||||
if departure.destination.starts_with(&station_properties.name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut after_current_station = false;
|
||||
if departure.initialStopPlace == station_properties.code {
|
||||
after_current_station = true;
|
||||
}
|
||||
|
||||
let mut stops_at_destination = false;
|
||||
for stop in &departure.route {
|
||||
@ -277,13 +292,15 @@ async fn route_station_to_dest_station(
|
||||
|
||||
if stops_at_destination {
|
||||
out.push_str(&format!("<li><time datetime=\"{}\">{}</time>: ", departure_info.time, departure_time.format("%H:%M")));
|
||||
out.push_str(&format!("<a href=\"https://bahn.expert/details/{}%20{}/{}?evaNumberAlongRoute={}\">", &departure.train.r#type, &departure.train.number, &departure.initialDeparture, station_properties.code));
|
||||
out.push_str(&format!("<a href=\"https://bahn.expert/details/{}%20{}/{}?evaNumberAlongRoute={}\">", &departure.train.r#type, &departure.train.number, &departure.initial_departure, station_properties.code));
|
||||
out.push_str(&format!("{} ({} {})</a>", &departure.train.name, &departure.train.r#type, &departure.train.number));
|
||||
out.push_str(&format!("[{}]-> {}\n", departure_info.platform, &departure.destination));
|
||||
}
|
||||
}
|
||||
|
||||
out.push_str("</ul></body></html>\n");
|
||||
out.push_str("</ul>\n");
|
||||
out.push_str("<p><small><a href=\"/\">Nur Ausstieg</a> | <a href=\"https://git.clerie.de/clerie/nurausstieg\">Source Code</a></small></p>\n");
|
||||
out.push_str("</body></html>\n");
|
||||
|
||||
return Ok(Html(out));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user