About
This crate provides a Rust API to communicate with the undocumented MVG (Münchner Verkehrsgesellschaft) API.
See the example section below, which shows how to query timetable information
and more for public transport in and around Munich.
Since no information about an official API could be found on the MVG developer website,
credit and thanks go to this Python project,
which documents some of the available endpoints.
Right now, this is very much a work in progress, as only a "happy path" solution is implemented,
which basically only documents the API endpoints.
Disclaimer
This is not an official project. Please acknowledge the imprint on the official MVG website
and respect the copyright section, which states:
[...]
Our systems are used for direct customer interaction.
The processing of our content or data by third parties requires our express consent.
For private, non-commercial purposes, moderate use is tolerated without our express consent.
Any form of data mining does not constitute moderate use. [...]
Examples
#[tokio::main]
async fn main() {
let locations = mvg::locations("Starnberg Nord").await.unwrap();
for l in locations.iter().take(3) {
println!("{:?}", l.name.as_ref().unwrap());
}
let starnberg_nord_gid = locations.first().unwrap().global_id.as_ref().unwrap();
mvg::departures(starnberg_nord_gid)
.await
.unwrap()
.iter()
.take(3)
.for_each(|d| {
println!(
"{} {} {} - {}",
d.transport_type.as_ref().unwrap(),
d.label.as_ref().unwrap(),
d.destination.as_ref().unwrap(),
ts_to_hms(d.realtime_departure_time.unwrap() / 1000)
)
});
let frauenkirche = (48.138611, 11.573889);
mvg::nearby_locations(frauenkirche.0, frauenkirche.1)
.await
.unwrap()
.iter()
.take(3)
.for_each(|l| {
println!(
"{} - {} meters",
l.name.as_ref().unwrap(),
l.distance_in_meters.unwrap(),
)
});
let stations = mvg::stations().await.unwrap();
stations.iter().take(3).for_each(|s| {
println!(
"{} - ({}, {})",
s.name.as_ref().unwrap(),
s.latitude.unwrap(),
s.longitude.unwrap()
)
});
let station_global_ids = mvg::station_global_ids().await.unwrap();
station_global_ids
.iter()
.take(3)
.for_each(|id| println!("{id}"));
let lines = mvg::lines().await.unwrap();
lines.iter().take(3).for_each(|l| {
println!(
"{} - {}",
l.name.as_ref().unwrap(),
l.product.as_ref().unwrap()
)
});
}