summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstuebinm2022-02-01 19:56:48 +0100
committerstuebinm2022-02-01 19:56:48 +0100
commit6af74791f87f812516d0158f9124a70d4943e194 (patch)
tree290f99bb336e2eb222a4d69e790175693fd4fa22
parentd6c0c640e64fceba6c280d76ee64d44831e9afef (diff)
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?)
-rw-r--r--src/main.rs23
-rw-r--r--src/types.rs2
2 files changed, 24 insertions, 1 deletions
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<Station>,
+ pub to_station: Option<Station>,
intermediate_stops: Vec<Stop>,
train: Option<Train>,
action_time: u64,