Skip to content

valemaio2/NextBus-GB-API-Python-parser

Repository files navigation

An improved Python NextBuses API Parser

This is a fork of the GitLab project below:

https://gitlab.developers.cam.ac.uk/cscs/nextbuses-api-python-parser

Summary of changes from the original project:

  • In bus.py, made it so the expected and scheduled departure times are shown in the local timezone, rather than in UTC
  • In config.json, added the parameter "num_departures": 6, so that you can choose how many arrivals to show for each bus stop. Of course, change 6 to whatever value you need.

NextBus API

To be able to use this parser, you will need to request a NextBus API account. As of writing this, they provide 180,000 free hits every 6 months. To request access to the API, please follow this link:

https://www.travelinedata.org.uk/traveline-open-data/nextbuses-api/

Once you are given access to the API, you will be given a set of username and password which will be used by the API parser, and stored in config.json file.

Bus stop ATCO code

The parser expects the ATCO code for the bus stop, while Google Maps shows the Naptan code for it. You can download the list of ATCO codes for your local transport authority from here:

https://beta-naptan.dft.gov.uk/download/la

I have included the bus stop code list for Cardiff in file bus stop codes.xlsx, but you will need to find the list for your local authority.

Usage:

  • Install python3 and pip
  • Install pip requirements in requirements.txt (Flask, flask-cors, requests)
  • Optional: set up python environment with python -m venv /path/to/your/environment
  • Search bus stop in google maps and copy bus stop ID
  • Open spreadsheet file from https://beta-naptan.dft.gov.uk/download/la, search for bus stop ID and copy matching ATCOcode
  • Edit config.json with desired bus stop code and number of departures to show, plus your NextBus API username and password
  • Run the parser and HTML page builder with: python sync.py config.json && python generate.py config.json
  • The resulting page will be in html/buses.html

Original project description from GitLab:

Simple Python NextBuses API Parser and HTML Display

This project is a very simple implementation of the NextBuses API (https://www.travelinedata.org.uk/traveline-open-data/nextbuses-api/).

This allows you to easily get live bus timetable information from the UK's live bus data network.

TODO: Finish documentation beyond simple overview.

Setup

pip3 install -r requirements.txt

config.json

Copy config.json.template to config.json and update with your API credentials.

You can customize the data and html paths in here as well.

Static Page Generator - Installation

There are two calls needed to generate a HTML display page:

python3 sync.py /path/to/config.json
python3 generate.py /path/to/config.json

sync.py should be schedule to download an updated set of files on a regualar schedule. generate.py will operate from this cached data file.

About

A Python parser for the NextBus API

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •