version = "0.1.0"
dependencies = [
"ascii_table",
+ "chrono",
"clap",
"mta_live_client",
]
edition = "2021"
[dependencies]
-mta_live_client = { path = "../mta_live_client" }
-clap = { version = "4", features = ["derive"] }
ascii_table = { version = "4" }
+chrono = { version = "0" }
+clap = { version = "4", features = ["derive"] }
+mta_live_client = { path = "../mta_live_client" }
use std::fmt::Display;
use ascii_table::AsciiTable;
+use chrono::TimeDelta;
use clap::Parser;
/// Dump upcoming train ETAs at a given stop
fn main() {
let args = Args::parse();
- let stop_responses = mta_live_client::get_nearby(&HashSet::from([&args.stop_id])).unwrap();
+ let stop_responses = mta_live_client::get_nearby(
+ &HashSet::from([&args.stop_id]),
+ TimeDelta::minutes(60), // maximum window size supported by API
+ )
+ .unwrap();
let stop_response = match stop_responses.len() {
1 => stop_responses.into_iter().next().unwrap(),
length => panic!("expected 1 stop response from API, got {length}"),
edition = "2021"
[dependencies]
-reqwest = { version = "0.12", features = ["blocking", "json"] }
-serde_json = { version = "1" }
-serde = { version = "1", features = ["derive"] }
chrono = { version = "0" }
clap = { version = "4", features = ["derive"] }
+reqwest = { version = "0.12", features = ["blocking", "json"] }
+serde = { version = "1", features = ["derive"] }
+serde_json = { version = "1" }
use std::collections::HashSet;
use chrono::offset::FixedOffset;
-use chrono::DateTime;
+use chrono::{DateTime, TimeDelta};
use reqwest::Url;
use serde::Deserialize;
pub fn get_nearby(
stop_ids: &HashSet<impl AsRef<str>>,
+ window_size: TimeDelta,
) -> Result<Vec<StopResponse>, reqwest::Error> {
+ assert!(
+ window_size >= TimeDelta::zero(),
+ "expected non-negative window size"
+ );
let url = Url::parse_with_params(
"https://otp-mta-prod.camsys-apps.com/otp/routers/default/nearby",
- &[(
- "stops",
- stop_ids
- .iter()
- .map(AsRef::as_ref)
- .collect::<Vec<_>>()
- .join(","),
- )],
+ &[
+ (
+ "stops",
+ stop_ids
+ .iter()
+ .map(AsRef::as_ref)
+ .collect::<Vec<_>>()
+ .join(","),
+ ),
+ ("timeRange", window_size.num_seconds().to_string()),
+ ],
)
.unwrap();
reqwest::blocking::get(url)?.json()