At Open Innovations we like buses. We like Bus Open Data. We want to be able to archive Bus Open Data. This is our prototype for creating an archive of BODS data.
You should also ensure you have a python environment set up for this project. To make managing that easier, we use pipenv. If you don't already have pipenv installed, you can do so by running:
pip install pipenvOnce pipenv is installed, you can load the environment for this project by running the following command at the root of this directory:
pipenv syncWhen running Python scripts, you should do so inside a pipenv shell, which you can load by running:
pipenv shellThis will install all the necessary packages and ensure the correct versions. You can see a full list of commands by running pipenv -h.
The archive is made up of several subtasks. Both should be set up using a cronjob. Edit the crontab using:
crontab -eThen add the following:
BODSARCHIVE=/path/to/archive
30 02 * * * /path/to/scripts/timetable.sh
* * * * * /path/to/scripts/archive.shThis will download the timetables at 2:30am each day. Note that these tend to take up roughly 1.3GB per day.
The archive script will download two files per minute.
If you want to run the scripts manually, you should set an environment variable:
export BODSARCHIVE=/path/to/archiveThe timetable data for each region (in GTFS format) can be downloaded by running scripts/timetable.sh. This will save the files in:
${BODSARCHIVE}/timetables/YYYY/MM/DD/itm_REGION_NAME_gtfs_YYMMDD.zip
The real time data for each region is downloaded by running scripts/archive.sh. This saves files of the form:
${BODSARCHIVE}/sirivm/YYYY/MM/DD/sirivm-YYYYMMDDTHHMMSS.zip${BODSARCHIVE}/gtfsrt/YYYY/MM/DD/gtfsrt-YYYYMMDDTHHMMSS.zip
Running this will save two files for both gtfsrt and sirivm, 30s apart. This is because we use the same script for cronjob (see above).
To make the outputs easier to use in a variety of situations we create simplified (de-duplicated and rounded) CSV versions of the real-time data using:
pipenv run python scripts/python/gtfsrt_to_csv.pyThis will look for all the GTFS-RT zip files from yesterday and output a zipped CSV file in:
${BODSARCHIVE}/csv/YYYY/csv-YYYMMDD.csv.zip
You can also explicitly set which day's data gets processed using e.g.
pipenv run python scripts/python/gtfsrt_to_csv.py --date "2025/05/29"If the output file already exists you can force it to overwrite it using the --force flag:
pipenv run python scripts/python/gtfsrt_to_csv.py --date "2025/05/29" --forceDownload entire days from the archive.
pipenv run python scripts/python/BulkDownloader.pySee how well bus operators report their journeys in BODS
pipenv run python scripts/python/OperatorPerformance.py -d "yyyymmdd"Pre-requisites: Use BulkDownloader.py to get the archive files for a given day as a zip.
The Archive Downloader script is a Python program designed to download gtfsrt or sirivm bus location data files from a the BODS archive based on user-defined date ranges.
Make sure you follow the steps to set-up your Python environment.
To run the script, you need to provide several command-line arguments. Here’s how to use it:
-s,--sd: Start date in the formatYYYY/mm/dd. Default is2025/07/01.-e,--ed: End date in the formatYYYY/mm/dd. Default is2025/07/01.-f,--format: Data format to download. Options aregtfsrtorsirivm. Default isgtfsrt.-o,--outpath: Output directory to store downloaded files, relative to the current working directory. Default isdata.
To download data from July 1, 2025, to July 3, 2025, in the gtfsrt format and save it in a folder named downloads, you would run:
python archive_downloader.py -s 2025/07/01 -e 2025/07/03 -f gtfsrt -o downloads- The script only downloads files that match the naming pattern
format-YYYYMMDDTHHMMSS.zip. - If a link does not match the expected format or is not a zip file, it will be skipped with a printed message.
- The script will print status messages for each link processed, including any errors encountered during the download process.