This tool fetches information about current journeys of a given transit route using the TrafikLab APIs. The data is only available for Stockholm, Sweden. The script checks the expected and actual time of departure/arrival by stop, for all the current journeys of the route. When each journey finishes, its final values are appended to a CSV file. The script tries to make the least number of requests, with five retries at most in case of error.
- Install
pipenv
- Clone/download this repository
- Inside the folder, run
pipenv install
- Fetch the API keys from Trafiklab (see below).
API_KEY=<Your API key> SERVICE="Bus 550" ORIGIN=9703 DESTINATION=5889 pipenv run python main.py
Optional parameter FREQ
can be used to set the iteration frequency (in minutes). Default: 1 minute.
The api key is the one for the Trafiklab's TravelPlanner V3.1 API.
The ids of origins and destinations can be fetched with the Trafiklab's Platsuppslag API, which can be done directly with the find_site
script included in this repo (see next).
This script allows you to find the site_id
of any place in Stockholm. To use it, you need the Platsuppslag API key.
API_KEY=<Your API key> pipenv run python find_site.py Stora Torget
To get your API keys, you have to create a project in Trafiklab, enable the desired APIs, and generate the keys.