Skip to main content

Get transport information from TransportNSW

Project description

TransportNSW

Python lib to access Transport NSW information.

How to Use

Get an API Key

An OpenData account and API key is required to request the data. More information on how to create the free account can be found here: https://opendata.transport.nsw.gov.au/user-guide .

Get the stop and line

The libary will expect at least stop id to request the next leave events. The easieste way to get the ID is using Google Maps and clicking on one of the bus, train or ferry stops. The information pane one the left will show the relevant stop ID.

Another source for the stop ID and line is https://transportnsw.info/stops#/. It provides the option to search for a stop and the corresponding lines leaving from there.

Sample Code

The following example will request the next leave event for the bus route/line 199 from stop ID 209516.

Code:

from TransportNSW import TransportNSW
ptnsw1 = TransportNSW.TransportNSW()
journey = tnsw.get_departures('209516', '199', '', 'YOUR_API_KEY')
print(journey)

Result:

{'stop_id': '209516', 'route': '199', 'due': 4, 'delay': 0, 'real_time': 'n', 'destination': 'Palm Beach'}
  • route: bus, train, ferry number
  • due: minutes till next leave
  • real_time: flag if the leave event has real_time information
  • delay: delay in minutes from the scheduled leave time
  • destination: end point of the route

Leaving the line field empty will return any bus/train/ferry leaving next from a given stop. Code:

journey = tnsw.get_departures('209516', '', '', 'YOUR_API_KEY')

Setting a destination will return all lines going there from the stop_id. Example for ferries leaving Balmain Warf towards Circular Quay Code:

journey = tnsw.get_departures('10102008','','Circular Quay' 'YOUR_API_KEY')

Errors

No leave event with wrong stop ID or not matching route.

{'stop_id': 'n/a', 'route': 'n/a', 'due': 'n/a', 'delay': 'n/a', 'real_time': 'n/a', destination: 'n/a'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyTransportNSW-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyTransportNSW-0.1.0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file PyTransportNSW-0.1.0.tar.gz.

File metadata

  • Download URL: PyTransportNSW-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for PyTransportNSW-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5b4e8d58679be0a673e7da16b92a374f26fcafd50a3b1e04121c9864e24eacb3
MD5 55b4814bb398382baef03ec2128f9442
BLAKE2b-256 2142694ad5138607d71d5010d748e9e0a558e57e2b80c1b974622d13c0326386

See more details on using hashes here.

File details

Details for the file PyTransportNSW-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: PyTransportNSW-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for PyTransportNSW-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0eccc52cd9b5b0c012352e98eba51ded245071478397169adc8a0247c0ab9c98
MD5 b29d352b4d27bdf069228da878c290c8
BLAKE2b-256 509372eaeca0bd590b0bbdf7a4ba7c68708fe16e11660d9ba97584bcbfa7ab57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page