Get detailed per-trip 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. You need to register an application that needs both the Trip Planner and Realtime Vehicle Positions APIs
Get the stop IDs
The library needs the stop ID for the source and destination, and optionally how many minutes from now the departure should be. The easiest way to get the stop ID is via https://transportnsw.info/stops#/. It provides the option to search for either a location or a specific platform, bus stop or ferry wharf. Regardless of if you specify a general location for the origin or destination, the return information shows the stop_id for the actual arrival and destination platform, bus stop or ferry wharf.
If it's available, the general occupancy level and the latitude and longitude of the selected journey's vehicle (train, bus, etc) will be returned.
API Documentation
The source API details can be found here: https://opendata.transport.nsw.gov.au/node/601/exploreapi
Parameters
.get_trip(origin_stop_id, destination_stop_id, api_key, [trip_wait_time = 0])
Sample Code
The following example will return the next trip from Gordon Station to Pymble Station, without specifying a platform.
Code:
from TransportNSW import TransportNSW
tnsw = TransportNSW()
journey = tnsw.get_trip('10101121', '10101123', 'YOUR_API_KEY')
print(journey)
Result:
{'due': 5, 'origin_stop_id': '207263', 'origin_name': 'Gordon Station', 'origin_detail': 'Platform 3', 'departure_time': '2020-06-14T10:21:30Z', 'destination_stop_id': '2073162', 'destination_name': 'Pymble Station', 'destination_detail': 'Platform 2', 'arrival_time': '2020-06-14T10:23:30Z', 'transport_type': 'Train', 'transport_name': 'Sydney Trains Network', 'line_name': 'T1 North Shore & Western Line', 'line_name_short': 'T1', 'occupancy': 'UNKNOWN', 'real_time_trip_id': '104P.1379.110.128.T.8.61720413', 'latitude': -33.76505661010742, 'longitude': 151.1614227294922}
- due: the time (in minutes) before the vehicle arrives
- origin_stop_id: the specific departure stop id
- origin_name: the name of the general departure location
- origin_detail: the specific departure location
- arrival_time: the arrival time at the origin
- transport_type: the type of transport, eg train, bus, ferry etc
- transport_name: the full name of transport providere
- line_name & line_name_short: the full and short names of the journey
- occupancy: how full the vehicle is
- real_time_trip_id: the unique TransportNSW id for that specific journey
- latitude & longitude: The location of the vehicle, if available
To do:
- Add an option to filter by specific transport type, useful if the general departure and arrival ids are being used
- Add an option to show brief vs verbose information
Thank you
Thank you Dav0815 for your TransportNSW library that the vast majority of this fork is based on. I couldn't have done it without you!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file PyTransportNSWv2-0.2.4.tar.gz
.
File metadata
- Download URL: PyTransportNSWv2-0.2.4.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 502510acfc371f159956814a148beeac94cde0c56da0057ae3d93d3c19ce3989 |
|
MD5 | 5be57dc9cea1f11176d00fd9aae4691c |
|
BLAKE2b-256 | 0d8409e9ba5bbe086ad0b956d5b898e6e8340f151694738fc04da2420cb4ad8d |
File details
Details for the file PyTransportNSWv2-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: PyTransportNSWv2-0.2.4-py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f318f9a8876b0a2366dfc120b4754350f5d511304b0b4717b3825cb35d3b341 |
|
MD5 | c02283f8116d610376e8e1b65f5bdc3d |
|
BLAKE2b-256 | 9a332f9c9ce69411f77b5cbbdde4fcc1aaaf8fcd28f7d5865c041f9dbf95ede9 |