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 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/main.rs') 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), -- cgit v1.2.3