The timetable website of SBB (Swiss Federal Railways) has become unbearable to use. So I built my own timetable.
How Did We Get Here?
I have always been a fan of the Swiss railway system. It’s punctual, efficient, and can get you into almost any corner of Switzerland within a reasonable timeframe.
My biggest grievance with their service, however, is their timetable website which they provide at sbb.ch. The website is horribly bloated. When loading (I deactivated my adblocker for this), it currently clocks in at 3.89 MB. The website is filled mostly with ads for their special offers. Funnily enough, only 0.86 MB accounts for images, while javascript libraries use more than twice that (2.1 MB). The rest is split into 0.41 MB of CSS and other miscellaneous things like SVG graphics and HTML. Simply loading the website fires of 53 requests. Before you can even start to search, you of course have to accept their cookie use or click through their policy to decline.
Since I use SBB more frequently than the average passenger, I usually know where I want to go and I only need the time. I also can’t use the SBB app on my phone, because they only publish the app on the Google Play Store.
Being frustrated with that, I decided to create my own timetable web app.
The OpenData.ch API
OpenData.ch is the open data initiative in Switzerland. While checking their websites and examples, I saw that they provided an SBB timetable here. In fact, I had been using it for several years as a drop-in replacement for the SBB timetable.
With a very limited feature set, it did the trick for me most of the time. However, I wanted to extend it to my own needs. Luckily they provide the source code on Github, so I was able to check their code, and replicate it for my needs. It’s a simple wrapper around the OpenData transport API.
The example was written in PHP, which I’d used for a long time, so it was easy to adapt. Since I have my own webspace, I decided to use PHP as well. My version is now available at https://t.grwlr.ch.
OpenData API is Limited
The API by OpenData of course is limited, as the SBB are able to provide more information. The key differences of the OpenData API to the SBB website are:
- no capacity information and seat availability for 1st and 2nd class
- no accurate information about delays
- tighter time windows for changing connections (which for me is usually not a problem)
Additionally, the returned connections are sometimes weird with “Walk for 48 minutes from A to B, then get on the train to C”. I’m now filtering out connections with more than 15 minutes of walking.
Conclusion
I’m quite happy with my results and plan to extend and adapt it further to my needs. As I’m the only user (that I know of), it’s easier to build and not care about small bugs.