mirror of
https://gitlab.com/Anson-Projects/gtfs_realtime_parser.git
synced 2025-06-15 14:36:41 +00:00
init commit
This commit is contained in:
commit
a246f0156c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"rust-analyzer.check.command": "clippy"
|
||||
}
|
1319
Cargo.lock
generated
Normal file
1319
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
16
Cargo.toml
Normal file
16
Cargo.toml
Normal file
@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "gtfs_realtime_parser"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Anson Biggs anson@ansonbiggs.com"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bytes = "1.5.0"
|
||||
prost = "0.12"
|
||||
reqwest = "0.11"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
|
||||
[build-dependencies]
|
||||
prost-build = { version = "0.12" }
|
5
build.rs
Normal file
5
build.rs
Normal file
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
prost_build::Config::new()
|
||||
.out_dir(std::env::var("OUT_DIR").unwrap())
|
||||
.compile_protos(&["proto/transit_realtime.proto"], &["proto/"]).unwrap();
|
||||
}
|
1035
proto/transit_realtime.proto
Normal file
1035
proto/transit_realtime.proto
Normal file
File diff suppressed because it is too large
Load Diff
32
src/main.rs
Normal file
32
src/main.rs
Normal file
@ -0,0 +1,32 @@
|
||||
// Include the module generated from the .proto file
|
||||
include!(concat!(env!("OUT_DIR"), "/transit_realtime.rs"));
|
||||
|
||||
use prost::Message;
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
// Denver RTD realtime vehicle positions
|
||||
let url = "https://rtd.prod.acquia-sites.com/files/gtfs-rt/VehiclePosition.pb";
|
||||
|
||||
let response = reqwest::get(url).await?;
|
||||
let bytes = response.bytes().await?;
|
||||
|
||||
|
||||
|
||||
let feed = FeedMessage::decode(bytes.as_ref())?;
|
||||
|
||||
dbg!(&feed);
|
||||
for entity in feed.entity {
|
||||
let vehicle = entity.vehicle.unwrap();
|
||||
let position = vehicle.position.unwrap();
|
||||
println!(
|
||||
"Vehicle ID: {}, Latitude: {}, Longitude: {}",
|
||||
vehicle.vehicle.unwrap().id.unwrap(),
|
||||
position.latitude,
|
||||
position.longitude
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user