PyTransportNSWv2 0.6.0__tar.gz → 0.6.5__tar.gz
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.6.0 → PyTransportNSWv2-0.6.5}/PKG-INFO +8 -4
- {PyTransportNSWv2-0.6.0 → PyTransportNSWv2-0.6.5}/PyTransportNSWv2.egg-info/PKG-INFO +8 -4
- {PyTransportNSWv2-0.6.0 → PyTransportNSWv2-0.6.5}/README.md +7 -3
- {PyTransportNSWv2-0.6.0 → PyTransportNSWv2-0.6.5}/TransportNSWv2/TransportNSWv2.py +31 -25
- {PyTransportNSWv2-0.6.0 → PyTransportNSWv2-0.6.5}/setup.py +1 -1
- {PyTransportNSWv2-0.6.0 → PyTransportNSWv2-0.6.5}/LICENSE +0 -0
- {PyTransportNSWv2-0.6.0 → PyTransportNSWv2-0.6.5}/PyTransportNSWv2.egg-info/SOURCES.txt +0 -0
- {PyTransportNSWv2-0.6.0 → PyTransportNSWv2-0.6.5}/PyTransportNSWv2.egg-info/dependency_links.txt +0 -0
- {PyTransportNSWv2-0.6.0 → PyTransportNSWv2-0.6.5}/PyTransportNSWv2.egg-info/requires.txt +0 -0
- {PyTransportNSWv2-0.6.0 → PyTransportNSWv2-0.6.5}/PyTransportNSWv2.egg-info/top_level.txt +0 -0
- {PyTransportNSWv2-0.6.0 → PyTransportNSWv2-0.6.5}/TransportNSWv2/__init__.py +0 -0
- {PyTransportNSWv2-0.6.0 → PyTransportNSWv2-0.6.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: PyTransportNSWv2
|
3
|
-
Version: 0.6.
|
3
|
+
Version: 0.6.5
|
4
4
|
Summary: Get detailed per-trip transport information from TransportNSW
|
5
5
|
Home-page: https://github.com/andystewart999/TransportNSW
|
6
6
|
Author: andystewart999
|
@@ -15,7 +15,7 @@ Description: # TransportNSWv2
|
|
15
15
|
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
|
16
16
|
|
17
17
|
### Get the stop IDs
|
18
|
-
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.
|
18
|
+
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, or to only include trips that have specific text somewhere in the line/service details (see below). 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.
|
19
19
|
|
20
20
|
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.
|
21
21
|
|
@@ -24,7 +24,7 @@ Description: # TransportNSWv2
|
|
24
24
|
|
25
25
|
### Parameters
|
26
26
|
```python
|
27
|
-
.get_trip(origin_stop_id, destination_stop_id, api_key, [trip_wait_time = 0], [transport_type = 0], [strict_transport_type = True|False], [raw_output = True|False], [journeys_to_return = 1] )
|
27
|
+
.get_trip(origin_stop_id, destination_stop_id, api_key, [trip_wait_time = 0], [transport_type = 0], [strict_transport_type = True|False], [raw_output = True|False], [journeys_to_return = 1], [route_filter = ''] )
|
28
28
|
```
|
29
29
|
|
30
30
|
Transport types:
|
@@ -58,6 +58,9 @@ Description: # TransportNSWv2
|
|
58
58
|
```python
|
59
59
|
{"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}
|
60
60
|
```
|
61
|
+
|
62
|
+
```origin_line_name``` and ```origin_line_name_short``` are the fields that have the route filter applied, if present. For buses they are usually the same, but for trains and ferries they generally show the full and short line names. Both fields are checked and if either meet the filter then the journey is returned.
|
63
|
+
|
61
64
|
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 it.
|
62
65
|
|
63
66
|
* due: the time (in minutes) before the journey starts
|
@@ -76,7 +79,8 @@ Description: # TransportNSWv2
|
|
76
79
|
* latitude & longitude: The location of the vehicle, if available
|
77
80
|
|
78
81
|
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.
|
79
|
-
|
82
|
+
|
83
|
+
Also note that the 'transport_type' filter, if present, only makes sure that at least one leg of the journey includes that transport type unless 'strict_transport_type' is True, in which case the first leg MUST be of the requested type to be returned.
|
80
84
|
|
81
85
|
## Thank you
|
82
86
|
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!
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: PyTransportNSWv2
|
3
|
-
Version: 0.6.
|
3
|
+
Version: 0.6.5
|
4
4
|
Summary: Get detailed per-trip transport information from TransportNSW
|
5
5
|
Home-page: https://github.com/andystewart999/TransportNSW
|
6
6
|
Author: andystewart999
|
@@ -15,7 +15,7 @@ Description: # TransportNSWv2
|
|
15
15
|
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
|
16
16
|
|
17
17
|
### Get the stop IDs
|
18
|
-
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.
|
18
|
+
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, or to only include trips that have specific text somewhere in the line/service details (see below). 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.
|
19
19
|
|
20
20
|
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.
|
21
21
|
|
@@ -24,7 +24,7 @@ Description: # TransportNSWv2
|
|
24
24
|
|
25
25
|
### Parameters
|
26
26
|
```python
|
27
|
-
.get_trip(origin_stop_id, destination_stop_id, api_key, [trip_wait_time = 0], [transport_type = 0], [strict_transport_type = True|False], [raw_output = True|False], [journeys_to_return = 1] )
|
27
|
+
.get_trip(origin_stop_id, destination_stop_id, api_key, [trip_wait_time = 0], [transport_type = 0], [strict_transport_type = True|False], [raw_output = True|False], [journeys_to_return = 1], [route_filter = ''] )
|
28
28
|
```
|
29
29
|
|
30
30
|
Transport types:
|
@@ -58,6 +58,9 @@ Description: # TransportNSWv2
|
|
58
58
|
```python
|
59
59
|
{"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}
|
60
60
|
```
|
61
|
+
|
62
|
+
```origin_line_name``` and ```origin_line_name_short``` are the fields that have the route filter applied, if present. For buses they are usually the same, but for trains and ferries they generally show the full and short line names. Both fields are checked and if either meet the filter then the journey is returned.
|
63
|
+
|
61
64
|
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 it.
|
62
65
|
|
63
66
|
* due: the time (in minutes) before the journey starts
|
@@ -76,7 +79,8 @@ Description: # TransportNSWv2
|
|
76
79
|
* latitude & longitude: The location of the vehicle, if available
|
77
80
|
|
78
81
|
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.
|
79
|
-
|
82
|
+
|
83
|
+
Also note that the 'transport_type' filter, if present, only makes sure that at least one leg of the journey includes that transport type unless 'strict_transport_type' is True, in which case the first leg MUST be of the requested type to be returned.
|
80
84
|
|
81
85
|
## Thank you
|
82
86
|
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!
|
@@ -8,7 +8,7 @@ An OpenData account and API key is required to request the data. More informatio
|
|
8
8
|
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
|
9
9
|
|
10
10
|
### Get the stop IDs
|
11
|
-
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.
|
11
|
+
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, or to only include trips that have specific text somewhere in the line/service details (see below). 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.
|
12
12
|
|
13
13
|
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.
|
14
14
|
|
@@ -17,7 +17,7 @@ The source API details can be found here: https://opendata.transport.nsw.gov.au/
|
|
17
17
|
|
18
18
|
### Parameters
|
19
19
|
```python
|
20
|
-
.get_trip(origin_stop_id, destination_stop_id, api_key, [trip_wait_time = 0], [transport_type = 0], [strict_transport_type = True|False], [raw_output = True|False], [journeys_to_return = 1] )
|
20
|
+
.get_trip(origin_stop_id, destination_stop_id, api_key, [trip_wait_time = 0], [transport_type = 0], [strict_transport_type = True|False], [raw_output = True|False], [journeys_to_return = 1], [route_filter = ''] )
|
21
21
|
```
|
22
22
|
|
23
23
|
Transport types:
|
@@ -51,6 +51,9 @@ print(journey)
|
|
51
51
|
```python
|
52
52
|
{"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
53
|
```
|
54
|
+
|
55
|
+
```origin_line_name``` and ```origin_line_name_short``` are the fields that have the route filter applied, if present. For buses they are usually the same, but for trains and ferries they generally show the full and short line names. Both fields are checked and if either meet the filter then the journey is returned.
|
56
|
+
|
54
57
|
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 it.
|
55
58
|
|
56
59
|
* due: the time (in minutes) before the journey starts
|
@@ -69,7 +72,8 @@ Fun fact: TransportNSW's raw API output calls itself JSON, but it uses single q
|
|
69
72
|
* latitude & longitude: The location of the vehicle, if available
|
70
73
|
|
71
74
|
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.
|
72
|
-
|
75
|
+
|
76
|
+
Also note that the 'transport_type' filter, if present, only makes sure that at least one leg of the journey includes that transport type unless 'strict_transport_type' is True, in which case the first leg MUST be of the requested type to be returned.
|
73
77
|
|
74
78
|
## Thank you
|
75
79
|
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!
|
@@ -71,7 +71,7 @@ class TransportNSWv2(object):
|
|
71
71
|
}
|
72
72
|
|
73
73
|
def get_trip(self, name_origin, name_destination , api_key, journey_wait_time = 0, transport_type = 0, \
|
74
|
-
strict_transport_type = False, raw_output = False, journeys_to_return = 1):
|
74
|
+
strict_transport_type = False, raw_output = False, journeys_to_return = 1, route_filter = ''):
|
75
75
|
"""Get the latest data from Transport NSW."""
|
76
76
|
fmt = '%Y-%m-%dT%H:%M:%SZ'
|
77
77
|
|
@@ -83,6 +83,7 @@ class TransportNSWv2(object):
|
|
83
83
|
self.strict_transport_type = strict_transport_type
|
84
84
|
self.raw_output = raw_output
|
85
85
|
self.journeys_to_return = journeys_to_return
|
86
|
+
self.route_filter = route_filter
|
86
87
|
|
87
88
|
# This query always uses the current date and time - but add in any 'journey_wait_time' minutes
|
88
89
|
now_plus_wait = datetime.now() + timedelta(minutes = journey_wait_time)
|
@@ -141,19 +142,14 @@ class TransportNSWv2(object):
|
|
141
142
|
no_valid_journeys = False
|
142
143
|
|
143
144
|
for current_journey_index in range (0, retrieved_journeys, 1):
|
144
|
-
|
145
|
-
|
146
|
-
journey = result['journeys'][current_journey_index]
|
147
|
-
next_journey_index = current_journey_index + 1
|
148
|
-
else:
|
149
|
-
# Look for a trip with a matching class filter in at least one of its legs. Either ANY, or the first leg, depending on how strict we're being
|
150
|
-
journey, next_journey_index = self.find_next_journey(result['journeys'], current_journey_index, transport_type, strict_transport_type)
|
145
|
+
# Look for a trip with a matching transport type filter in at least one of its legs. Either ANY, or the first leg, depending on how strict we're being
|
146
|
+
journey, next_journey_index = self.find_next_journey(result['journeys'], current_journey_index, transport_type, strict_transport_type, route_filter)
|
151
147
|
|
152
148
|
if ((journey is None) or (journey['legs']) is None):
|
153
149
|
pass
|
154
150
|
else:
|
155
151
|
legs = journey['legs']
|
156
|
-
first_leg = self.find_first_leg(legs, transport_type, strict_transport_type)
|
152
|
+
first_leg = self.find_first_leg(legs, transport_type, strict_transport_type, route_filter)
|
157
153
|
|
158
154
|
#Executive decision - don't be strict on the last leg, there's often some walking (transport type 100) involved.
|
159
155
|
last_leg = self.find_last_leg(legs, transport_type, False)
|
@@ -295,8 +291,8 @@ class TransportNSWv2(object):
|
|
295
291
|
# return None
|
296
292
|
|
297
293
|
|
298
|
-
def find_next_journey(self, journeys, start_journey_index, journeytype, strict):
|
299
|
-
# Fnd the next journey that has a leg of the requested type
|
294
|
+
def find_next_journey(self, journeys, start_journey_index, journeytype, strict, route_filter):
|
295
|
+
# Fnd the next journey that has a leg of the requested type, and/or that satisfies the route filter
|
300
296
|
journey_count = len(journeys)
|
301
297
|
|
302
298
|
# Some basic error checking
|
@@ -304,7 +300,7 @@ class TransportNSWv2(object):
|
|
304
300
|
return None, None
|
305
301
|
|
306
302
|
for journey_index in range (start_journey_index, journey_count, 1):
|
307
|
-
leg = self.find_first_leg(journeys[journey_index]['legs'], journeytype, strict)
|
303
|
+
leg = self.find_first_leg(journeys[journey_index]['legs'], journeytype, strict, route_filter)
|
308
304
|
if leg is not None:
|
309
305
|
return journeys[journey_index], journey_index + 1
|
310
306
|
else:
|
@@ -314,22 +310,32 @@ class TransportNSWv2(object):
|
|
314
310
|
return None, None
|
315
311
|
|
316
312
|
|
317
|
-
def find_first_leg(self, legs, legtype, strict):
|
313
|
+
def find_first_leg(self, legs, legtype, strict, route_filter):
|
318
314
|
# Find the first leg of the requested type
|
319
315
|
leg_count = len(legs)
|
320
316
|
for leg_index in range (0, leg_count, 1):
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
return
|
317
|
+
#First, check against the route filter
|
318
|
+
origin_line_name_short = 'n/a'
|
319
|
+
origin_line_name = 'n/a'
|
320
|
+
|
321
|
+
if 'transportation' in legs[leg_index]:
|
322
|
+
if 'disassembledName' in legs[leg_index]['transportation']:
|
323
|
+
origin_line_name_short = legs[leg_index]['transportation']['disassembledName']
|
324
|
+
origin_line_name = legs[leg_index]['transportation']['number']
|
325
|
+
|
326
|
+
if (route_filter in origin_line_name_short or route_filter in origin_line_name):
|
327
|
+
leg_class = legs[leg_index]['transportation']['product']['class']
|
328
|
+
# We've got a filter, and the leg type matches it, so return that leg
|
329
|
+
if legtype != 0 and leg_class == legtype:
|
330
|
+
return legs[leg_index]
|
331
|
+
|
332
|
+
# We don't have a filter, and this is the first non-walk/cycle leg so return that leg
|
333
|
+
if legtype == 0 and leg_class < 99:
|
334
|
+
return legs[leg_index]
|
335
|
+
|
336
|
+
# Exit if we're doing strict filtering and we haven't found that type in the first leg
|
337
|
+
if legtype != 0 and strict == True:
|
338
|
+
return None
|
333
339
|
|
334
340
|
# Hmm, we didn't find one
|
335
341
|
return None
|
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
|
5
5
|
|
6
6
|
setuptools.setup(
|
7
7
|
name="PyTransportNSWv2",
|
8
|
-
version="0.6.
|
8
|
+
version="0.6.5",
|
9
9
|
author="andystewart999",
|
10
10
|
description="Get detailed per-trip transport information from TransportNSW",
|
11
11
|
long_description=long_description,
|
File without changes
|
File without changes
|
{PyTransportNSWv2-0.6.0 → PyTransportNSWv2-0.6.5}/PyTransportNSWv2.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|