Structure of JSON generated
This commit is contained in:
parent
57d8cdfd23
commit
bccfc22770
@ -17,3 +17,7 @@ datetime = "0.5.2"
|
||||
# Necessary for web crawler
|
||||
openssl = { version = "0.10", features = ["vendored"] }
|
||||
reqwest = { version = "0.11", features = ["blocking", "json"] }
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
# end of web stuff
|
||||
|
@ -2,12 +2,62 @@
|
||||
* @brief fetch next depature of light rail vehicle
|
||||
*/
|
||||
use std::error::Error;
|
||||
use serde::Deserialize;
|
||||
|
||||
const stationURL:&str = "https://www.rnv-online.de/rest/departure/2494/1";
|
||||
const stationURL:&str = "https://www.rnv-online.de/rest/departure/2494";
|
||||
|
||||
pub fn fetchData() -> Result<(), Box<dyn Error>> {
|
||||
println!("Test RNV API");
|
||||
let resp = reqwest::blocking::get(stationURL)?.text()?;
|
||||
println!("{:#?}", resp);
|
||||
Ok(())
|
||||
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Station {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub lines: Vec<Line>,
|
||||
pub journeys: Vec<Journey>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Line {
|
||||
pub id: i64,
|
||||
pub text: String,
|
||||
pub iconOutlined: i64,
|
||||
pub iconColor: String,
|
||||
pub iconTextColor: i64,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Journey {
|
||||
pub line: Line,
|
||||
pub destination: String,
|
||||
pub barrierLevel: String,
|
||||
pub loadsForecastType: String,
|
||||
pub realtimeDeparture: i64,
|
||||
pub scheduledDeparture: i64,
|
||||
pub difference: i64,
|
||||
pub canceled: bool,
|
||||
}
|
||||
|
||||
pub struct NextDeparture {
|
||||
pub rheinau: i64,
|
||||
pub schoenau: i64,
|
||||
}
|
||||
|
||||
|
||||
pub fn fetchData() -> Result<String, reqwest::Error> {
|
||||
let result = reqwest::blocking::get(stationURL);
|
||||
|
||||
let response = match result {
|
||||
Ok(res) => res,
|
||||
Err(err) => return reqwest::Error(err),
|
||||
};
|
||||
|
||||
let body = serde_json::from_str(&text);
|
||||
|
||||
let json = match body {
|
||||
Ok(json) => json,
|
||||
Err(err) => return reqwest::Error(err),
|
||||
};
|
||||
let date = json["id"].to_string();
|
||||
Ok(date)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user