PyTransportNSWv2 0.3.0__py3-none-any.whl → 0.3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {PyTransportNSWv2-0.3.0.dist-info → PyTransportNSWv2-0.3.1.dist-info}/METADATA +17 -14
- PyTransportNSWv2-0.3.1.dist-info/RECORD +7 -0
- TransportNSW/TransportNSW.py +17 -3
- PyTransportNSWv2-0.3.0.dist-info/RECORD +0 -7
- {PyTransportNSWv2-0.3.0.dist-info → PyTransportNSWv2-0.3.1.dist-info}/LICENSE +0 -0
- {PyTransportNSWv2-0.3.0.dist-info → PyTransportNSWv2-0.3.1.dist-info}/WHEEL +0 -0
- {PyTransportNSWv2-0.3.0.dist-info → PyTransportNSWv2-0.3.1.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: PyTransportNSWv2
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.1
|
4
4
|
Summary: Get detailed per-trip transport information from TransportNSW
|
5
5
|
Home-page: https://github.com/andystewart999/TransportNSW
|
6
6
|
Author: andystewart999
|
@@ -23,7 +23,7 @@ An OpenData account and API key is required to request the data. More informatio
|
|
23
23
|
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
|
24
24
|
|
25
25
|
### Get the stop IDs
|
26
|
-
The
|
26
|
+
The function needs the stop IDs for the source and destination, and optionally how many minutes from now the departure should be, and if you want to filter trips by a specific transport type. 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.
|
27
27
|
|
28
28
|
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.
|
29
29
|
|
@@ -32,42 +32,45 @@ The source API details can be found here: https://opendata.transport.nsw.gov.au/
|
|
32
32
|
|
33
33
|
### Parameters
|
34
34
|
```python
|
35
|
-
.get_trip(origin_stop_id, destination_stop_id, api_key, [trip_wait_time = 0])
|
35
|
+
.get_trip(origin_stop_id, destination_stop_id, api_key, [trip_wait_time = 0], [transport_type = 0])
|
36
36
|
```
|
37
37
|
|
38
|
-
TransportNSW's trip planner
|
38
|
+
TransportNSW's trip planner can work better if you use the general location IDs (eg Central Station) rather than a specific Stop ID (eg Central Station, Platform 19) for the destination, depending on the transport type. Forcing a specific end destination sometimes results in much more complicated trips. Also note that the API expects (and returns) the Stop IDs as strings, although so far they all appear to be numeric.
|
39
39
|
|
40
40
|
### Sample Code
|
41
|
-
|
41
|
+
|
42
|
+
The following example will return the next trip that starts from a bus stop in St. Ives (207537) five minutes from now, to Central Station's general stop ID (10101100):
|
42
43
|
|
43
44
|
**Code:**
|
44
45
|
```python
|
45
46
|
from TransportNSW import TransportNSW
|
46
47
|
tnsw = TransportNSW()
|
47
|
-
journey = tnsw.get_trip('207537', '10101100', 'YOUR_API_KEY')
|
48
|
+
journey = tnsw.get_trip('207537', '10101100', 'YOUR_API_KEY', 5)
|
48
49
|
print(journey)
|
49
50
|
```
|
50
51
|
**Result:**
|
51
52
|
```python
|
52
|
-
{
|
53
|
+
{"due": 3, "origin_stop_id": "207537", "origin_name": "Mona Vale Rd at Shinfield Ave, St Ives", "departure_time": "2024-05-20T21:59:48Z", "destination_stop_id": "2000338", "destination_name": "Central Station, Platform 18, Sydney", "arrival_time": "2024-05-20T22:47:36Z", "origin_transport_type": "Bus", "origin_transport_name": "Sydney Buses Network", "origin_line_name": "195", "origin_line_name_short": "195", "changes": 1, "occupancy": "MANY_SEATS", "real_time_trip_id": "2096551", "latitude": -33.72665786743164, "longitude": 151.16305541992188}
|
53
54
|
```
|
55
|
+
Fun fact: TransportNSW's raw API output calls itself JSON, but it uses single quotes for strings in defiance of the JSON standards. When using this wrapper the output is formatted such that `jq`, for example, is happy with.
|
54
56
|
|
55
|
-
* due: the time (in minutes) before the journey starts
|
57
|
+
* due: the time (in minutes) before the journey starts
|
56
58
|
* origin_stop_id: the specific departure stop id
|
57
59
|
* origin_name: the name of the departure location
|
58
|
-
* departure_time: the departure time
|
60
|
+
* departure_time: the departure time, in UTC
|
59
61
|
* destination_stop_id: the specific destination stop id
|
60
62
|
* destination_name: the name of the destination location
|
61
|
-
* arrival_time: the arrival time at the origin
|
63
|
+
* arrival_time: the planned arrival time at the origin, in UTC
|
62
64
|
* origin_transport_type: the type of transport, eg train, bus, ferry etc
|
63
|
-
* origin_transport_name: the full name of transport
|
65
|
+
* origin_transport_name: the full name of the transport provider
|
64
66
|
* origin_line_name & origin_line_name_short: the full and short names of the journey
|
65
|
-
* changes: how many transport changes are needed
|
67
|
+
* changes: how many transport changes are needed on the journey
|
66
68
|
* occupancy: how full the vehicle is, if available
|
67
|
-
* real_time_trip_id: the unique TransportNSW id for that specific journey
|
69
|
+
* real_time_trip_id: the unique TransportNSW id for that specific journey, if available
|
68
70
|
* latitude & longitude: The location of the vehicle, if available
|
69
71
|
|
70
|
-
Please note that the origin and destination detail is just that. We don't return any intermediate steps, transport change types etc other than the total number of changes
|
72
|
+
Please note that the origin and destination detail is just that - information about the first and last stops on the journey at the time the request was made. We don't return any intermediate steps, transport change types etc other than the total number of changes - the assumption is that you'll know the details of your specified trip, you just want to know when the next departure is. If you need much more detailed information then I recommend that you use the full Transport NSW trip planner website or application.
|
73
|
+
Also note that the 'transport_type' filter, if present, only makes sure that at least one leg of the journey includes that transport type.
|
71
74
|
|
72
75
|
## Thank you
|
73
76
|
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!
|
@@ -0,0 +1,7 @@
|
|
1
|
+
TransportNSW/TransportNSW.py,sha256=dKbYIRSLJUqmJHDH5ZOdLWK5mObW4uxGb89l1Um9_-k,13395
|
2
|
+
TransportNSW/__init__.py,sha256=O3iuSkUGkkDz4C7IlqvOXJHPJTxYz0q_48-94ESlkdg,86
|
3
|
+
PyTransportNSWv2-0.3.1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
4
|
+
PyTransportNSWv2-0.3.1.dist-info/METADATA,sha256=fFZtnw4SXZZfkjGktIEW29Qaj3Re0QDPmxXfGmM2ddk,5326
|
5
|
+
PyTransportNSWv2-0.3.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
+
PyTransportNSWv2-0.3.1.dist-info/top_level.txt,sha256=C4LQEkr85VJtG9cklBu9IFpSKRaNSADPBTSPeXIYnOw,13
|
7
|
+
PyTransportNSWv2-0.3.1.dist-info/RECORD,,
|
TransportNSW/TransportNSW.py
CHANGED
@@ -8,6 +8,7 @@ import requests.exceptions
|
|
8
8
|
import requests
|
9
9
|
import logging
|
10
10
|
import re
|
11
|
+
import json #For the output
|
11
12
|
|
12
13
|
ATTR_DUE_IN = 'due'
|
13
14
|
|
@@ -131,6 +132,14 @@ class TransportNSW(object):
|
|
131
132
|
# Look for a trip with a matching class filter in at least one of its legs. Could possibly be more stringent here, if ANY part of the journey fits the filter, it will be returned.
|
132
133
|
journey = self.find_first_journey(result['journeys'], transport_type)
|
133
134
|
|
135
|
+
if journey is None:
|
136
|
+
logger.warning("No journey information returned")
|
137
|
+
return self.info
|
138
|
+
|
139
|
+
if journey['legs'] is None:
|
140
|
+
logger.warning("No journey information returned")
|
141
|
+
return self.info
|
142
|
+
|
134
143
|
legs = journey['legs']
|
135
144
|
first_leg = self.find_first_leg(legs, transport_type)
|
136
145
|
last_leg = self.find_last_leg(legs, transport_type)
|
@@ -168,8 +177,13 @@ class TransportNSW(object):
|
|
168
177
|
realtimetripid = transportation['properties']['RealtimeTripId']
|
169
178
|
|
170
179
|
# Line info
|
171
|
-
origin_line_name_short =
|
172
|
-
|
180
|
+
origin_line_name_short = "unknown"
|
181
|
+
if 'disassembledName' in transportation:
|
182
|
+
origin_line_name_short = transportation['disassembledName']
|
183
|
+
|
184
|
+
origin_line_name = "unknown"
|
185
|
+
if 'number' in transportation:
|
186
|
+
origin_line_name = transportation['number']
|
173
187
|
|
174
188
|
# Occupancy info, if it's there
|
175
189
|
occupancy = 'UNKNOWN'
|
@@ -242,7 +256,7 @@ class TransportNSW(object):
|
|
242
256
|
ATTR_LATITUDE : latitude,
|
243
257
|
ATTR_LONGITUDE : longitude
|
244
258
|
}
|
245
|
-
return self.info
|
259
|
+
return json.dumps(self.info)
|
246
260
|
|
247
261
|
def find_first_journey(self, journeys, journeytype):
|
248
262
|
# Find the first journey whose first leg is of the requested type
|
@@ -1,7 +0,0 @@
|
|
1
|
-
TransportNSW/TransportNSW.py,sha256=jjuFpL2FqIKAmDE0IvgULzLqO1QZ4tE-wrUHTYs9iwY,12930
|
2
|
-
TransportNSW/__init__.py,sha256=O3iuSkUGkkDz4C7IlqvOXJHPJTxYz0q_48-94ESlkdg,86
|
3
|
-
PyTransportNSWv2-0.3.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
4
|
-
PyTransportNSWv2-0.3.0.dist-info/METADATA,sha256=86_6bT24mMIYXlUWzLlEZ97fgyG3I9gdgokDcsMy2sU,4500
|
5
|
-
PyTransportNSWv2-0.3.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
PyTransportNSWv2-0.3.0.dist-info/top_level.txt,sha256=C4LQEkr85VJtG9cklBu9IFpSKRaNSADPBTSPeXIYnOw,13
|
7
|
-
PyTransportNSWv2-0.3.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|