#data #amtrak #information #vehicle #convert #valid #gtfs-rt

amtrak-gtfs-rt

Converts Amtrak Track-A-Train to valid GTFS-rt vehicle and trip information

26 releases

0.4.1 Nov 2, 2024
0.3.2 Oct 12, 2024
0.2.6 May 14, 2024
0.2.0 Mar 27, 2024
0.1.12 Dec 30, 2023

#9 in #valid

Download history 63/week @ 2024-07-29 136/week @ 2024-08-05 103/week @ 2024-08-12 10/week @ 2024-08-19 62/week @ 2024-08-26 82/week @ 2024-09-02 21/week @ 2024-09-09 57/week @ 2024-09-16 99/week @ 2024-09-23 180/week @ 2024-09-30 382/week @ 2024-10-07 206/week @ 2024-10-14 228/week @ 2024-10-21 284/week @ 2024-10-28 70/week @ 2024-11-04 83/week @ 2024-11-11

686 downloads per month
Used in 3 crates (2 directly)

AGPL-3.0

48KB
699 lines

amtrak-gtfs-rt

Decrypts Amtrak's GTFS-RT

A valid Amtrak GTFS structure must be passed into the function to work.

Here's an example of some working code!

The latest version of prost should be used along with the gtfs-realtime crate library.

extern crate amtrak_gtfs_rt;

use prost::Message;
use gtfs_structures::Gtfs;

#[tokio::main]
async fn main() {
    let gtfs = Gtfs::from_url_async("https://content.amtrak.com/content/gtfs/GTFS.zip")
    .await
    .unwrap();

    let client = reqwest::Client::new();
    loop {
        let amtrak_gtfs_rt = amtrak_gtfs_rt::fetch_amtrak_gtfs_rt(&gtfs, &client).await.unwrap();

        //extract the binary data
        let vehicle_data = amtrak_gtfs_rt.vehicle_positions.encode_to_vec();
        let trip_data = amtrak_gtfs_rt.trip_updates.encode_to_vec();

        std::thread::sleep(std::time::Duration::from_millis(500));
    }
}

This software package decrypts the Amtrak track-a-train json data and performs lookups of trip information in the GTFS schedule to match each vehicle with it's route_id and trip_id.

Pull requests are welcome!

Capital Corridor Exception

Note that the Metropolitan Transportation Commission also publishes Capital Corridor in their own feed. https://511.org/open-data/transit provides Capital Corridor as "CC". This data refreshes more often (and is closer in location & time), and shows locomotive numbers. For this reason, you may wish to remove Capital Corridor from this feed. Thus, we've included a function filter_capital_corridor() which takes in any gtfs_rt::FeedMessage and removes CC vehicles and trips.

Dependencies

~19–34MB
~514K SLoC