From 80a4af9f0a6f7e3bd2d8254f8bc8475ca73b8980 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Tue, 1 Feb 2022 17:41:56 +0100 Subject: display iceportal itinery & stops I'm pretty sure something in parsing the times is broken, since this train is currently /also/ broken I have absolutely no idea what the correct ones would be and don't have the energy to dig further into this. --- src/iceportal.rs | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/iceportal.rs') diff --git a/src/iceportal.rs b/src/iceportal.rs index 1b36556..a81d5d3 100644 --- a/src/iceportal.rs +++ b/src/iceportal.rs @@ -1,7 +1,8 @@ +use chrono::NaiveDateTime; use serde::Deserialize; use serde_json::Value; -use crate::travelynx::TrainRef; +use crate::{travelynx::TrainRef, types::IsStation, serde::*}; #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] @@ -24,9 +25,10 @@ struct Trip { #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] -struct Stop { +pub struct Stop { info: StopInfo, - station: Station + station: Station, + timetable: Timetable } #[derive(Deserialize, Debug)] @@ -43,6 +45,33 @@ struct Station { name: String } +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +struct Timetable { + #[serde(deserialize_with = "option_naive_read_unixtime")] + scheduled_arrival_time: Option, + #[serde(deserialize_with = "option_naive_read_unixtime")] + actual_arrival_time: Option +} + +impl IsStation for Stop { + fn name (&self) -> &str { + &self.station.name + } + + fn scheduled_arrival (&self) -> Option<&chrono::NaiveDateTime> { + self.timetable.scheduled_arrival_time.as_ref() + } + + fn real_arrival (&self) -> Option<&chrono::NaiveDateTime> { + self.timetable.actual_arrival_time.as_ref() + } + + fn ds100 (&self) -> &str { + "??" + } +} + impl TripInfo { @@ -64,4 +93,8 @@ impl TripInfo { no: self.trip.vzn.clone() } } + + pub fn trip (&self) -> crate::types::Trip<'_,Stop> { + crate::types::Trip(&self.trip.stops) + } } -- cgit v1.2.3