This Rust program is designed to retrieve information about upcoming trains arriving at a specified station. It utilizes the Washington Metropolitan Area Transit Authority (WMATA) API to fetch real-time train predictions.
This project was developed in a 24 hour code challenge for a Job Interview.
Ensure you have Rust installed on your system. If not, you can install it from Rust's official website.
Clone this repository to your local machine and navigate into it:
git clone https://github.com/cyeganeh01248/MetroStatus.git
cd MetroStatus
In order to install locally, run the following script.
cargo build --release
In order to install via Docker, run the following script.
docker build -t metro_status .
Before running the program, you need to obtain an API key from WMATA. You can register for an API key here.
Once you have the API key, you can pass it as a command-line argument.
If you do not obtain one, you may leave the argument out. The default public demo key will be used. This key has significantly low limits and is more used for testing purposes.
To run the program locally, execute the following command:
cargo run -- [--api-key YOUR_API_KEY] [--target-station TARGET_STATION_NAME]
To then run the program with docker, execute the following command:
docker run --rm -it metro_status [--api-key YOUR_API_KEY] [--target-station TARGET_STATION_NAME]
If desired, replace YOUR_API_KEY
with your WMATA API Key and TARGET_STATION_NAME
with the name of the station you
want to fetch train schedules for. Leaving off the TARGET_STATION_NAME
will default to Huntington Station.
You may also provide your API key by providing a value to the API_KEY
environment variable.
--api-key
/-a
: The WMATA API key to use. Defaults to a public demo key if not provided.--target-station
/-t
: The name of the station to look for. Defaults to "Huntington" if not provided.
This program utilizes the following external crates:
clap
: A command-line argument parsing library for parsing command-line options.tokio
: An async framework for rust for running async functions such as the reqwest lib.reqwest
: An Async Rust HTTP client for making requests to the WMATA API.serde
: A serialization/deserialization library for converting JSON responses into Rust structs.