August 18, 2018
I enjoy hiking, which most of the times involves using public transportation to get to the start of my hike and to get back home. Planning these trips used to be a major chore in Hungary before 2016, as there was no unified schedule database: one could only plan trips by train or bus, not together. During these times I came up with a timetable format in which I manually collected transit options using the bus and train planner websites as well as a map to came up with potential routes. These days transit information is available via the Google Directions API, so I decided to revisit this format and I developed a script that creates it automatically.
Accessible transit data
Although menetrendek.hu, the official transit planner website in Hungary does not have a public API, they at least made train data available on Google Maps in October 2016 and the data for regional and national buses available in June 2017.
I have personally found local transit schedule websites (9292.nl in the Netherlands and the aforementioned menetrendek.hu in Hungary) to give better recommendations than Google, but without an open API I cannot use their data. Writing a script that uses the Google API also has the benefit of being portable across countries.
Google’s transit results are also available in Google Maps. However, I found the “Schedule Explorer” interface to be somewhat unintuitive (as you scroll, the displayed length of the trip might change) and buggy (sometimes when I click on a transit option to see the details I am presented with the details of a different option). It is also not possible to see all options for a day. Because of this, I still needed a better way to see all the results.
As it can be seen above, the timetable I generate is tightly packed with information. My goal was to get
- each leg of the trip
- depature and arrival localities, stations, and times
- vehicle (line) name and type (bus, train, etc) as well as destination (to know what to look for at the station)
- overall departure and arrival time and trip duration
and put it in a dense but easy to follow format. Based on this, I came up with the following format:
Luckily, this information is trivial to get from the Google Directions and Geocoding API as it can be seen in the GitHub repository with the code. I can now save a significant amount of time using this script: instead of manually copy-pasting trip details, I can generate the timetable with one click regardless of which country I am in.
 One could theoretically use their browser’s developer tools to listen in on the XHR requests the webiste makes to the server and write a documentation for the API themselves, but this would be probably illegal in Hungary, even if the API were not protected. In one case, a person was reported to the police for developing a good transit app for Debrecen, a large city in the country. In another case a man was arrested (later acquitted) for changing the transit ticket prices on the front end of Centre for Budapest Transport’s web shop. This price got sent to the back end so he bought a cheap season pass.
Originally published at hann.io on August 17, 2018.