Live and planned data extracted from JSON

This commit is contained in:
Ollo 2023-09-15 18:56:42 +02:00
parent 4fa63917ed
commit b897ec3739

View File

@ -60,10 +60,16 @@ pub struct Journey {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct StopsElement { pub struct StopsElement {
pub destinationLabel: String, pub destinationLabel: String,
//FIXME is in sub-structure: pub realtime_departure: Option<i64>, pub plannedDeparture: IsoStringDateTime,
//FIXME is in sub-structure: pub scheduled_departure: i64, pub realtimeDeparture: IsoStringDateTime,
//TODO pub difference: Option<i64>,
} }
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IsoStringDateTime {
pub isoString: Option<String>,
}
// Return value // Return value
pub struct NextDeparture { pub struct NextDeparture {
pub rheinau: i64, pub rheinau: i64,
@ -98,25 +104,14 @@ pub fn fetch_data() -> Option<&'static str> {
// parse JSON result.. search of both directions // parse JSON result.. search of both directions
let json = body.unwrap(); let json = body.unwrap();
for el in (json.graphQL.response.journeys.elements) { for el in (json.graphQL.response.journeys.elements) {
//TODO: println!("Line {:}", el.line.lineGroup.label);
/*let destination = (el.destination).to_string(); for stop in el.stops {
let departure = el.realtime_departure; if stop.realtimeDeparture.isoString.is_some() {
let difference = el.difference; println!("To {:} {:?}", stop.destinationLabel, stop.realtimeDeparture.isoString)
} else {
if departure.is_some() { println!("Planned {:} {:?}", stop.destinationLabel, stop.plannedDeparture.isoString)
// get current time }
let time_s = departure.unwrap();
let local_time = NaiveDateTime::from_timestamp_millis(time_s*1000).unwrap();
let zoned_time : DateTime<Utc> = DateTime::from_utc(local_time, Utc);
let europe_time = zoned_time.with_timezone(&Berlin);
let hour = europe_time.hour();
let minute = europe_time.minute();
if zoned_time > cur_time {
println!("------------- Future starts here ----------------");
} }
println!("{0} {1}:{2}", destination, hour, minute);
}*/
} }
Some("") Some("")