summaryrefslogtreecommitdiff
path: root/src/iceportal.rs
diff options
context:
space:
mode:
authorstuebinm2022-02-01 17:41:56 +0100
committerstuebinm2022-02-01 17:42:59 +0100
commit80a4af9f0a6f7e3bd2d8254f8bc8475ca73b8980 (patch)
treea2077ce6d328f2b94d0394fa1590c0cc5feac6fe /src/iceportal.rs
parentaacb2d78a4a97e3e8d7fdff4c06cba8be5f3139f (diff)
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.
Diffstat (limited to 'src/iceportal.rs')
-rw-r--r--src/iceportal.rs39
1 files changed, 36 insertions, 3 deletions
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<NaiveDateTime>,
+ #[serde(deserialize_with = "option_naive_read_unixtime")]
+ actual_arrival_time: Option<NaiveDateTime>
+}
+
+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)
+ }
}