use chrono::NaiveDateTime; use serde::Deserialize; #[derive(Deserialize)] pub struct DeparturesMerklingen { #[serde(rename = "entries")] pub entries: Vec, } #[derive(Deserialize)] pub struct DeparturesMerklingen1 { #[serde(rename = "zeit")] pub time_schedule: Option, #[serde(rename = "ezZeit")] pub time_delayed: Option, #[serde(rename = "ezGleis")] pub platform: Option, #[serde(rename = "gleis")] pub platform_schedule: Option, // TODO: find this in api if it exists #[serde(rename = "canceled")] pub canceled: Option, #[serde(rename = "verkehrmittel")] pub line_name: Option, // TODO: find this in api if it exists #[serde(rename = "stopPlace")] pub stop_place: Option, #[serde(rename = "terminus")] pub destination: Option, #[serde(rename = "meldungen")] pub messages: Option>, } #[derive(Deserialize)] pub struct DeparturesMerklingen4 { #[serde(rename = "linienNummer")] pub line_number: Option, #[serde(rename = "kurzText")] pub product: Option, } #[derive(Deserialize)] pub struct DeparturesMerklingen2 { #[serde(rename = "name")] pub name: Option, #[serde(rename = "canceled")] pub canceled: Option, } #[derive(Deserialize)] pub struct DeparturesMerklingen3 { #[serde(rename = "text")] pub text: Option, #[serde(rename = "prioritaet")] pub priority: Option, } pub async fn departures_merklingen() -> Result { let url = r#"https://www.bahn.de/web/api/reiseloesung/abfahrten?ortExtId=8003983&mitVias=true&maxVias=8&verkehrsmittel[]=ICE&verkehrsmittel[]=EC_IC&verkehrsmittel[]=IR&verkehrsmittel[]=REGIONAL&verkehrsmittel[]=SBAHN"#; match reqwest::get(url).await { Ok(response) => match response.text().await { Ok(response) => match serde_json::from_str::(&response) { Ok(response) => Ok(response), Err(e) => Err(format!( "Couldn't parse HTTP response from URL {url:?}: {e}\nResponse was (raw):\n{response}" ))?, }, Err(e) => Err(format!("Couldn't get HTTP response from URL {url:?}: {e}"))?, }, Err(e) => Err(format!("Couldn't make GET request to URL {url:?}: {e}"))?, } }