From 6af74791f87f812516d0158f9124a70d4943e194 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Tue, 1 Feb 2022 19:56:48 +0100 Subject: are we there yet? (also why do people get up from their seats a solid nine minutes before the train is even scheduled to arrive at all?) --- src/main.rs | 23 +++++++++++++++++++++++ src/types.rs | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 6bac375..356db21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,7 @@ enum Command { Destination { to: String }, + Arewethereyet, /// If iceportal.de is available, ask it which train we're in and /// check in Autocheckin, @@ -92,6 +93,28 @@ fn main() -> Result<(), ureq::Error> { println!("{}: {}", traveltext, status); } + Command::Arewethereyet => { + let status: Status = exiting_get_request( + &format!("{}/api/v1/status/{}", cli.baseurl, config.token_status), + cli.debug, + ); + + match status.to_station { + None => println!("{}: Fahrt ins {}", traveltext, "Blaue".blue()), + Some(to) => { + let now = chrono::Utc::now(); + let duration = to.real_arrival().map(|dt| *dt - now); + match duration { + Some (d) => println!( + "{}: we'll be there in {} minutes", + traveltext, + d.num_minutes() + ), + None => println!("{}: I have no idea", traveltext) + } + } + } + }, Command::Checkin { from, to, train } => { let resp: Response = exiting_post_request( &format!("{}/api/v1/travel", cli.baseurl), diff --git a/src/types.rs b/src/types.rs index 2e4d2e1..f4947e2 100644 --- a/src/types.rs +++ b/src/types.rs @@ -124,7 +124,7 @@ pub struct Status { checked_in: bool, from_station: Station, #[serde(deserialize_with = "parse_optional_station")] - to_station: Option, + pub to_station: Option, intermediate_stops: Vec, train: Option, action_time: u64, -- cgit v1.2.3