PyTransportNSWv2 0.6.6__tar.gz → 0.7.0__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.
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.1
2
+ Name: PyTransportNSWv2
3
+ Version: 0.7.0
4
+ Summary: Get detailed per-trip transport information from TransportNSW
5
+ Home-page: https://github.com/andystewart999/TransportNSW
6
+ Author: andystewart999
7
+ License: UNKNOWN
8
+ Description: # TransportNSWv2
9
+ Python lib to access Transport NSW information.
10
+
11
+ ## How to Use
12
+
13
+ ### Get an API Key
14
+ 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:
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
+
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, 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
+
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, unless you specifically set ```include_realtime_location``` to ```False```.
21
+
22
+ ### API Documentation
23
+ The source API details can be found here: https://opendata.transport.nsw.gov.au/sites/default/files/2023-08/Trip%20Planner%20API%20manual-opendataproduction%20v3.2.pdf
24
+
25
+ ### Parameters
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], [route_filter = ''], [include_realtime_location = True], [include_alerts = 'none'], [alert_type = 'all'] )
28
+ ```
29
+
30
+ Transport types:
31
+ ```
32
+ 1: Train
33
+ 2: Metro
34
+ 4: Light rail
35
+ 5: Bus
36
+ 7: Coach
37
+ 9: Ferry
38
+ 11: School bus
39
+ 99: Walk
40
+ 100: Walk
41
+ 107: Cycle
42
+ ```
43
+
44
+ Alert priorities:
45
+ ```
46
+ veryLow
47
+ low
48
+ normal
49
+ high
50
+ veryHigh
51
+ ```
52
+ Specifying an alert priority in ```include_alerts``` means that any alerts of that priority or higher will be included in the output as a raw JSON array, basically a collation of the alerts that the Trip API sent back. If you've specified that alerts of a given priority should be included then by default ALL alert types will be included - you can limit the output to specific alert types by setting ```alert_type``` to something like ```'lineInfo|stopInfo|bannerInfo'```.
53
+
54
+ Alert types:
55
+ ```
56
+ routeInfo: Alerts relating to a specific route
57
+ lineInfo: Alerts relating to a specific journey
58
+ stopInfo: Alerts relating to specific stops
59
+ stopBlocking: Alerts relating to stop closures
60
+ bannerInfo: Alerts potentially relating to network-wide impacts
61
+ ```
62
+
63
+ 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.
64
+
65
+ ### Sample Code - bus journey, no alerts included
66
+
67
+ The following example returns the next trip that starts from a bus stop in St. Ives (207537) at least five minutes from now, to Central Station's general stop ID (200060):
68
+
69
+ **Code:**
70
+ ```python
71
+ from TransportNSWv2 import TransportNSWv2
72
+ tnsw = TransportNSWv2()
73
+ journey = tnsw.get_trip('207537', '200060', 'YOUR_API_KEY', journey_wait_time = 5, transport_type = 5)
74
+ print(journey)
75
+ ```
76
+ **Result:**
77
+ ```python
78
+ {"journeys_to_return": 1, "journeys_with_data": 1, "journeys": [
79
+ {"due": 22, "origin_stop_id": "207537", "origin_name": "Mona Vale Rd at Shinfield Ave, St Ives", "departure_time": "2024-09-10T06:34:24Z", "destination_stop_id": "207235", "destination_name": "Gordon Station, Stand C, Gordon", "arrival_time": "2024-09-
80
+ 10T06:40:36Z", "origin_transport_type": "Bus", "origin_transport_name": "Sydney Buses Network", "origin_line_name": "195", "origin_line_name_short": "195", "changes": 0, "occupancy": "FEW_SEATS", "real_time_trip_id": "2197645", "latitude": -33.728271484375,
81
+ "longitude": 151.1637420654297, "alerts": []
82
+ }]}
83
+ ```
84
+
85
+ ### Sample Code - train journey, all stop-related alerts normal priority or higher included
86
+
87
+ The following example return the next train journey that starts from Gordon (207537) to Central (200070) one minute from now. Two journeys have been requested, we want realtime locations if possible, and we also want lineInfo and stopInfo alerts of priority normal or higher:
88
+
89
+ **Code:**
90
+ ```python
91
+ from TransportNSWv2 import TransportNSWv2
92
+ tnsw = TransportNSWv2()
93
+ journey = tnsw.get_trip('207210', '200070', '<your API key>', journey_wait_time = 1,transport_type = 1, journeys_to_return = 2, raw_output = False, include_realtime_location = True, include_alerts = 'normal', alert_type = 'lineInfo|stopInfo')
94
+ print(journey)
95
+ ```
96
+ **Result:**
97
+ ```python
98
+ {"journeys_to_return": 2, "journeys_with_data": 2, "journeys":[
99
+ {"due": 8, "origin_stop_id": "207262", "origin_name": "Gordon Station, Platform 2, Gordon", "departure_time": "2024-09-10T05:18:00Z", "destination_stop_id": "2000338", "destination_name": "Central Station, Platform 18, Sydney", "arrival_time": "2024-09-
100
+ 10T05:54:00Z", "origin_transport_type": "Train", "origin_transport_name": "Sydney Trains Network", "origin_line_name": "T1 North Shore & Western Line", "origin_line_name_short": "T1", "changes": 0, "occupancy": "unknown", "real_time_trip_id":
101
+ "171L.1915.100.8.A.8.83064399", "latitude": -33.755828857421875, "longitude": 151.1542205810547, "alerts": [
102
+ {"priority": "normal", "id": "ems-39380", "version": 3, "type": "stopInfo", "infoLinks": [{"urlText": "Central Station Lift 20 between Central Walk and Platform 20/21 is not available", "url": "https://transportnsw.info/alerts/details#/ems-39380", "content":
103
+ "At Central Station Lift 20 between Central Walk and Platform 20/21 is temporarily out of service.\n\nIf you need help, ask staff or phone 02 9379 1777.", "subtitle": "Central Station Lift 20 between Central Walk and Platform 20/21 is not available",
104
+ "smsText": "Central Station Lift 20 between Central Walk and Platform 20/21 is not available", "speechText": "At Central Station Lift 20 between Central Walk and Platform 20/21 is temporarily out of service.\n\nIf you need help, ask staff or phone 02 9379
105
+ 1777.", "properties": {"publisher": "ems.comm.addinfo", "infoType": "stopInfo", "appliesTo": "departingArriving", "stopIDglobalID": "200060:2000340,2000341"}}
106
+ ]}
107
+ ]},
108
+ {"due": 11, "origin_stop_id": "207261", "origin_name": "Gordon Station, Platform 1, Gordon", "departure_time": "2024-09-10T05:21:00Z", "destination_stop_id": "2067141", "destination_name": "Chatswood Station, Platform 1, Chatswood", "arrival_time": "2024-09-
109
+ 10T05:30:00Z", "origin_transport_type": "Train", "origin_transport_name": "Sydney Trains Network", "origin_line_name": "T1 North Shore & Western Line", "origin_line_name_short": "T1", "changes": 0, "occupancy": "unknown", "real_time_trip_id":
110
+ "281G.1915.100.12.H.8.83062682", "latitude": -33.709938049316406, "longitude": 151.10427856445312, "alerts": [
111
+ {"priority": "normal", "id": "ems-38565", "version": 145217, "type": "lineInfo", "infoLinks": [{"urlText": "Metro services temporarily end by 10.30pmMonday to Thursday evenings between Chatswood and Sydenham, please check service times and plan your trip",
112
+ "url": "https://transportnsw.info/alerts/details#/ems-38565", "content": "<div>\n<div>For the first four weeks after opening, there are reduced operating hours from Monday to Thursday evenings in the City section between Chatswood and Sydenham to support
113
+ essential engineering and maintenance works during the early phases of operations.</div>\n<div>&nbsp;</div>\n<div>This is temporary and only affects services between Chatswood and Sydenham.&nbsp;Following the first four weeks, metro services will operate
114
+ between Tallawong and Sydenham on the normal timetable.</div>\n</div>", "subtitle": "Metro services temporarily end by 10.30pm Monday to Thursday evenings between Chatswood and Sydenham, please check service times and plan your trip", "smsText": "Metro
115
+ services temporarily end by 10.30pm Monday to Thursday evenings between Chatswood and Sydenham, please check service times and plan your trip", "speechText": "There are reduced operating hours from Monday to Thursday evenings in the City section between
116
+ Chatswood and Sydenham to support essential engineering and maintenance works during the early phases of operations.", "properties": {"publisher": "ems.comm.addinfo", "infoType": "lineInfo"}}
117
+ ]}
118
+ ]}
119
+ ]}
120
+ ```
121
+ (In this example you can see that the second journey is actually ending at Chatswood. I checked the raw API data and it does in fact have the last leg of the second journey as being at Chatswood but doesn't give any explanation as to why. Interesting.)
122
+
123
+ * due: the time (in minutes) before the journey starts
124
+ * origin_stop_id: the specific departure stop id
125
+ * origin_name: the name of the departure location
126
+ * departure_time: the departure time, in UTC
127
+ * destination_stop_id: the specific destination stop id
128
+ * destination_name: the name of the destination location
129
+ * arrival_time: the planned arrival time at the origin, in UTC
130
+ * origin_transport_type: the type of transport, eg train, bus, ferry etc
131
+ * origin_transport_name: the full name of the transport provider
132
+ * origin_line_name & origin_line_name_short: the full and short names of the journey
133
+ * changes: how many transport changes are needed on the journey
134
+ * occupancy: how full the vehicle is, if available
135
+ * real_time_trip_id: the unique TransportNSW id for that specific journey, if available
136
+ * latitude & longitude: The location of the vehicle, if available
137
+ * alerts: An array of alerts pertinent to that journey
138
+
139
+
140
+ ### Notes ###
141
+ Requesting multiple journeys to be returned doesn't always return that exact number of journeys. The API only ever returns five or six, and if you have any filters applied then that might further reduce the number of 'valid' journeys.
142
+
143
+ ```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.
144
+
145
+ Note also that the origin and destination details are 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.
146
+
147
+ 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.
148
+
149
+ ## Thank you
150
+ 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!
151
+ https://github.com/Dav0815/TransportNSW
152
+
153
+ Platform: UNKNOWN
154
+ Classifier: Programming Language :: Python :: 3
155
+ Classifier: License :: OSI Approved :: MIT License
156
+ Classifier: Operating System :: OS Independent
157
+ Classifier: Intended Audience :: Developers
158
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
159
+ Description-Content-Type: text/markdown
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.1
2
+ Name: PyTransportNSWv2
3
+ Version: 0.7.0
4
+ Summary: Get detailed per-trip transport information from TransportNSW
5
+ Home-page: https://github.com/andystewart999/TransportNSW
6
+ Author: andystewart999
7
+ License: UNKNOWN
8
+ Description: # TransportNSWv2
9
+ Python lib to access Transport NSW information.
10
+
11
+ ## How to Use
12
+
13
+ ### Get an API Key
14
+ 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:
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
+
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, 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
+
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, unless you specifically set ```include_realtime_location``` to ```False```.
21
+
22
+ ### API Documentation
23
+ The source API details can be found here: https://opendata.transport.nsw.gov.au/sites/default/files/2023-08/Trip%20Planner%20API%20manual-opendataproduction%20v3.2.pdf
24
+
25
+ ### Parameters
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], [route_filter = ''], [include_realtime_location = True], [include_alerts = 'none'], [alert_type = 'all'] )
28
+ ```
29
+
30
+ Transport types:
31
+ ```
32
+ 1: Train
33
+ 2: Metro
34
+ 4: Light rail
35
+ 5: Bus
36
+ 7: Coach
37
+ 9: Ferry
38
+ 11: School bus
39
+ 99: Walk
40
+ 100: Walk
41
+ 107: Cycle
42
+ ```
43
+
44
+ Alert priorities:
45
+ ```
46
+ veryLow
47
+ low
48
+ normal
49
+ high
50
+ veryHigh
51
+ ```
52
+ Specifying an alert priority in ```include_alerts``` means that any alerts of that priority or higher will be included in the output as a raw JSON array, basically a collation of the alerts that the Trip API sent back. If you've specified that alerts of a given priority should be included then by default ALL alert types will be included - you can limit the output to specific alert types by setting ```alert_type``` to something like ```'lineInfo|stopInfo|bannerInfo'```.
53
+
54
+ Alert types:
55
+ ```
56
+ routeInfo: Alerts relating to a specific route
57
+ lineInfo: Alerts relating to a specific journey
58
+ stopInfo: Alerts relating to specific stops
59
+ stopBlocking: Alerts relating to stop closures
60
+ bannerInfo: Alerts potentially relating to network-wide impacts
61
+ ```
62
+
63
+ 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.
64
+
65
+ ### Sample Code - bus journey, no alerts included
66
+
67
+ The following example returns the next trip that starts from a bus stop in St. Ives (207537) at least five minutes from now, to Central Station's general stop ID (200060):
68
+
69
+ **Code:**
70
+ ```python
71
+ from TransportNSWv2 import TransportNSWv2
72
+ tnsw = TransportNSWv2()
73
+ journey = tnsw.get_trip('207537', '200060', 'YOUR_API_KEY', journey_wait_time = 5, transport_type = 5)
74
+ print(journey)
75
+ ```
76
+ **Result:**
77
+ ```python
78
+ {"journeys_to_return": 1, "journeys_with_data": 1, "journeys": [
79
+ {"due": 22, "origin_stop_id": "207537", "origin_name": "Mona Vale Rd at Shinfield Ave, St Ives", "departure_time": "2024-09-10T06:34:24Z", "destination_stop_id": "207235", "destination_name": "Gordon Station, Stand C, Gordon", "arrival_time": "2024-09-
80
+ 10T06:40:36Z", "origin_transport_type": "Bus", "origin_transport_name": "Sydney Buses Network", "origin_line_name": "195", "origin_line_name_short": "195", "changes": 0, "occupancy": "FEW_SEATS", "real_time_trip_id": "2197645", "latitude": -33.728271484375,
81
+ "longitude": 151.1637420654297, "alerts": []
82
+ }]}
83
+ ```
84
+
85
+ ### Sample Code - train journey, all stop-related alerts normal priority or higher included
86
+
87
+ The following example return the next train journey that starts from Gordon (207537) to Central (200070) one minute from now. Two journeys have been requested, we want realtime locations if possible, and we also want lineInfo and stopInfo alerts of priority normal or higher:
88
+
89
+ **Code:**
90
+ ```python
91
+ from TransportNSWv2 import TransportNSWv2
92
+ tnsw = TransportNSWv2()
93
+ journey = tnsw.get_trip('207210', '200070', '<your API key>', journey_wait_time = 1,transport_type = 1, journeys_to_return = 2, raw_output = False, include_realtime_location = True, include_alerts = 'normal', alert_type = 'lineInfo|stopInfo')
94
+ print(journey)
95
+ ```
96
+ **Result:**
97
+ ```python
98
+ {"journeys_to_return": 2, "journeys_with_data": 2, "journeys":[
99
+ {"due": 8, "origin_stop_id": "207262", "origin_name": "Gordon Station, Platform 2, Gordon", "departure_time": "2024-09-10T05:18:00Z", "destination_stop_id": "2000338", "destination_name": "Central Station, Platform 18, Sydney", "arrival_time": "2024-09-
100
+ 10T05:54:00Z", "origin_transport_type": "Train", "origin_transport_name": "Sydney Trains Network", "origin_line_name": "T1 North Shore & Western Line", "origin_line_name_short": "T1", "changes": 0, "occupancy": "unknown", "real_time_trip_id":
101
+ "171L.1915.100.8.A.8.83064399", "latitude": -33.755828857421875, "longitude": 151.1542205810547, "alerts": [
102
+ {"priority": "normal", "id": "ems-39380", "version": 3, "type": "stopInfo", "infoLinks": [{"urlText": "Central Station Lift 20 between Central Walk and Platform 20/21 is not available", "url": "https://transportnsw.info/alerts/details#/ems-39380", "content":
103
+ "At Central Station Lift 20 between Central Walk and Platform 20/21 is temporarily out of service.\n\nIf you need help, ask staff or phone 02 9379 1777.", "subtitle": "Central Station Lift 20 between Central Walk and Platform 20/21 is not available",
104
+ "smsText": "Central Station Lift 20 between Central Walk and Platform 20/21 is not available", "speechText": "At Central Station Lift 20 between Central Walk and Platform 20/21 is temporarily out of service.\n\nIf you need help, ask staff or phone 02 9379
105
+ 1777.", "properties": {"publisher": "ems.comm.addinfo", "infoType": "stopInfo", "appliesTo": "departingArriving", "stopIDglobalID": "200060:2000340,2000341"}}
106
+ ]}
107
+ ]},
108
+ {"due": 11, "origin_stop_id": "207261", "origin_name": "Gordon Station, Platform 1, Gordon", "departure_time": "2024-09-10T05:21:00Z", "destination_stop_id": "2067141", "destination_name": "Chatswood Station, Platform 1, Chatswood", "arrival_time": "2024-09-
109
+ 10T05:30:00Z", "origin_transport_type": "Train", "origin_transport_name": "Sydney Trains Network", "origin_line_name": "T1 North Shore & Western Line", "origin_line_name_short": "T1", "changes": 0, "occupancy": "unknown", "real_time_trip_id":
110
+ "281G.1915.100.12.H.8.83062682", "latitude": -33.709938049316406, "longitude": 151.10427856445312, "alerts": [
111
+ {"priority": "normal", "id": "ems-38565", "version": 145217, "type": "lineInfo", "infoLinks": [{"urlText": "Metro services temporarily end by 10.30pmMonday to Thursday evenings between Chatswood and Sydenham, please check service times and plan your trip",
112
+ "url": "https://transportnsw.info/alerts/details#/ems-38565", "content": "<div>\n<div>For the first four weeks after opening, there are reduced operating hours from Monday to Thursday evenings in the City section between Chatswood and Sydenham to support
113
+ essential engineering and maintenance works during the early phases of operations.</div>\n<div>&nbsp;</div>\n<div>This is temporary and only affects services between Chatswood and Sydenham.&nbsp;Following the first four weeks, metro services will operate
114
+ between Tallawong and Sydenham on the normal timetable.</div>\n</div>", "subtitle": "Metro services temporarily end by 10.30pm Monday to Thursday evenings between Chatswood and Sydenham, please check service times and plan your trip", "smsText": "Metro
115
+ services temporarily end by 10.30pm Monday to Thursday evenings between Chatswood and Sydenham, please check service times and plan your trip", "speechText": "There are reduced operating hours from Monday to Thursday evenings in the City section between
116
+ Chatswood and Sydenham to support essential engineering and maintenance works during the early phases of operations.", "properties": {"publisher": "ems.comm.addinfo", "infoType": "lineInfo"}}
117
+ ]}
118
+ ]}
119
+ ]}
120
+ ```
121
+ (In this example you can see that the second journey is actually ending at Chatswood. I checked the raw API data and it does in fact have the last leg of the second journey as being at Chatswood but doesn't give any explanation as to why. Interesting.)
122
+
123
+ * due: the time (in minutes) before the journey starts
124
+ * origin_stop_id: the specific departure stop id
125
+ * origin_name: the name of the departure location
126
+ * departure_time: the departure time, in UTC
127
+ * destination_stop_id: the specific destination stop id
128
+ * destination_name: the name of the destination location
129
+ * arrival_time: the planned arrival time at the origin, in UTC
130
+ * origin_transport_type: the type of transport, eg train, bus, ferry etc
131
+ * origin_transport_name: the full name of the transport provider
132
+ * origin_line_name & origin_line_name_short: the full and short names of the journey
133
+ * changes: how many transport changes are needed on the journey
134
+ * occupancy: how full the vehicle is, if available
135
+ * real_time_trip_id: the unique TransportNSW id for that specific journey, if available
136
+ * latitude & longitude: The location of the vehicle, if available
137
+ * alerts: An array of alerts pertinent to that journey
138
+
139
+
140
+ ### Notes ###
141
+ Requesting multiple journeys to be returned doesn't always return that exact number of journeys. The API only ever returns five or six, and if you have any filters applied then that might further reduce the number of 'valid' journeys.
142
+
143
+ ```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.
144
+
145
+ Note also that the origin and destination details are 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.
146
+
147
+ 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.
148
+
149
+ ## Thank you
150
+ 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!
151
+ https://github.com/Dav0815/TransportNSW
152
+
153
+ Platform: UNKNOWN
154
+ Classifier: Programming Language :: Python :: 3
155
+ Classifier: License :: OSI Approved :: MIT License
156
+ Classifier: Operating System :: OS Independent
157
+ Classifier: Intended Audience :: Developers
158
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
159
+ Description-Content-Type: text/markdown
@@ -0,0 +1,144 @@
1
+ # TransportNSWv2
2
+ Python lib to access Transport NSW information.
3
+
4
+ ## How to Use
5
+
6
+ ### Get an API Key
7
+ 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:
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
+
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, 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
+
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, unless you specifically set ```include_realtime_location``` to ```False```.
14
+
15
+ ### API Documentation
16
+ The source API details can be found here: https://opendata.transport.nsw.gov.au/sites/default/files/2023-08/Trip%20Planner%20API%20manual-opendataproduction%20v3.2.pdf
17
+
18
+ ### Parameters
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], [route_filter = ''], [include_realtime_location = True], [include_alerts = 'none'], [alert_type = 'all'] )
21
+ ```
22
+
23
+ Transport types:
24
+ ```
25
+ 1: Train
26
+ 2: Metro
27
+ 4: Light rail
28
+ 5: Bus
29
+ 7: Coach
30
+ 9: Ferry
31
+ 11: School bus
32
+ 99: Walk
33
+ 100: Walk
34
+ 107: Cycle
35
+ ```
36
+
37
+ Alert priorities:
38
+ ```
39
+ veryLow
40
+ low
41
+ normal
42
+ high
43
+ veryHigh
44
+ ```
45
+ Specifying an alert priority in ```include_alerts``` means that any alerts of that priority or higher will be included in the output as a raw JSON array, basically a collation of the alerts that the Trip API sent back. If you've specified that alerts of a given priority should be included then by default ALL alert types will be included - you can limit the output to specific alert types by setting ```alert_type``` to something like ```'lineInfo|stopInfo|bannerInfo'```.
46
+
47
+ Alert types:
48
+ ```
49
+ routeInfo: Alerts relating to a specific route
50
+ lineInfo: Alerts relating to a specific journey
51
+ stopInfo: Alerts relating to specific stops
52
+ stopBlocking: Alerts relating to stop closures
53
+ bannerInfo: Alerts potentially relating to network-wide impacts
54
+ ```
55
+
56
+ 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.
57
+
58
+ ### Sample Code - bus journey, no alerts included
59
+
60
+ The following example returns the next trip that starts from a bus stop in St. Ives (207537) at least five minutes from now, to Central Station's general stop ID (200060):
61
+
62
+ **Code:**
63
+ ```python
64
+ from TransportNSWv2 import TransportNSWv2
65
+ tnsw = TransportNSWv2()
66
+ journey = tnsw.get_trip('207537', '200060', 'YOUR_API_KEY', journey_wait_time = 5, transport_type = 5)
67
+ print(journey)
68
+ ```
69
+ **Result:**
70
+ ```python
71
+ {"journeys_to_return": 1, "journeys_with_data": 1, "journeys": [
72
+ {"due": 22, "origin_stop_id": "207537", "origin_name": "Mona Vale Rd at Shinfield Ave, St Ives", "departure_time": "2024-09-10T06:34:24Z", "destination_stop_id": "207235", "destination_name": "Gordon Station, Stand C, Gordon", "arrival_time": "2024-09-
73
+ 10T06:40:36Z", "origin_transport_type": "Bus", "origin_transport_name": "Sydney Buses Network", "origin_line_name": "195", "origin_line_name_short": "195", "changes": 0, "occupancy": "FEW_SEATS", "real_time_trip_id": "2197645", "latitude": -33.728271484375,
74
+ "longitude": 151.1637420654297, "alerts": []
75
+ }]}
76
+ ```
77
+
78
+ ### Sample Code - train journey, all stop-related alerts normal priority or higher included
79
+
80
+ The following example return the next train journey that starts from Gordon (207537) to Central (200070) one minute from now. Two journeys have been requested, we want realtime locations if possible, and we also want lineInfo and stopInfo alerts of priority normal or higher:
81
+
82
+ **Code:**
83
+ ```python
84
+ from TransportNSWv2 import TransportNSWv2
85
+ tnsw = TransportNSWv2()
86
+ journey = tnsw.get_trip('207210', '200070', '<your API key>', journey_wait_time = 1,transport_type = 1, journeys_to_return = 2, raw_output = False, include_realtime_location = True, include_alerts = 'normal', alert_type = 'lineInfo|stopInfo')
87
+ print(journey)
88
+ ```
89
+ **Result:**
90
+ ```python
91
+ {"journeys_to_return": 2, "journeys_with_data": 2, "journeys":[
92
+ {"due": 8, "origin_stop_id": "207262", "origin_name": "Gordon Station, Platform 2, Gordon", "departure_time": "2024-09-10T05:18:00Z", "destination_stop_id": "2000338", "destination_name": "Central Station, Platform 18, Sydney", "arrival_time": "2024-09-
93
+ 10T05:54:00Z", "origin_transport_type": "Train", "origin_transport_name": "Sydney Trains Network", "origin_line_name": "T1 North Shore & Western Line", "origin_line_name_short": "T1", "changes": 0, "occupancy": "unknown", "real_time_trip_id":
94
+ "171L.1915.100.8.A.8.83064399", "latitude": -33.755828857421875, "longitude": 151.1542205810547, "alerts": [
95
+ {"priority": "normal", "id": "ems-39380", "version": 3, "type": "stopInfo", "infoLinks": [{"urlText": "Central Station Lift 20 between Central Walk and Platform 20/21 is not available", "url": "https://transportnsw.info/alerts/details#/ems-39380", "content":
96
+ "At Central Station Lift 20 between Central Walk and Platform 20/21 is temporarily out of service.\n\nIf you need help, ask staff or phone 02 9379 1777.", "subtitle": "Central Station Lift 20 between Central Walk and Platform 20/21 is not available",
97
+ "smsText": "Central Station Lift 20 between Central Walk and Platform 20/21 is not available", "speechText": "At Central Station Lift 20 between Central Walk and Platform 20/21 is temporarily out of service.\n\nIf you need help, ask staff or phone 02 9379
98
+ 1777.", "properties": {"publisher": "ems.comm.addinfo", "infoType": "stopInfo", "appliesTo": "departingArriving", "stopIDglobalID": "200060:2000340,2000341"}}
99
+ ]}
100
+ ]},
101
+ {"due": 11, "origin_stop_id": "207261", "origin_name": "Gordon Station, Platform 1, Gordon", "departure_time": "2024-09-10T05:21:00Z", "destination_stop_id": "2067141", "destination_name": "Chatswood Station, Platform 1, Chatswood", "arrival_time": "2024-09-
102
+ 10T05:30:00Z", "origin_transport_type": "Train", "origin_transport_name": "Sydney Trains Network", "origin_line_name": "T1 North Shore & Western Line", "origin_line_name_short": "T1", "changes": 0, "occupancy": "unknown", "real_time_trip_id":
103
+ "281G.1915.100.12.H.8.83062682", "latitude": -33.709938049316406, "longitude": 151.10427856445312, "alerts": [
104
+ {"priority": "normal", "id": "ems-38565", "version": 145217, "type": "lineInfo", "infoLinks": [{"urlText": "Metro services temporarily end by 10.30pmMonday to Thursday evenings between Chatswood and Sydenham, please check service times and plan your trip",
105
+ "url": "https://transportnsw.info/alerts/details#/ems-38565", "content": "<div>\n<div>For the first four weeks after opening, there are reduced operating hours from Monday to Thursday evenings in the City section between Chatswood and Sydenham to support
106
+ essential engineering and maintenance works during the early phases of operations.</div>\n<div>&nbsp;</div>\n<div>This is temporary and only affects services between Chatswood and Sydenham.&nbsp;Following the first four weeks, metro services will operate
107
+ between Tallawong and Sydenham on the normal timetable.</div>\n</div>", "subtitle": "Metro services temporarily end by 10.30pm Monday to Thursday evenings between Chatswood and Sydenham, please check service times and plan your trip", "smsText": "Metro
108
+ services temporarily end by 10.30pm Monday to Thursday evenings between Chatswood and Sydenham, please check service times and plan your trip", "speechText": "There are reduced operating hours from Monday to Thursday evenings in the City section between
109
+ Chatswood and Sydenham to support essential engineering and maintenance works during the early phases of operations.", "properties": {"publisher": "ems.comm.addinfo", "infoType": "lineInfo"}}
110
+ ]}
111
+ ]}
112
+ ]}
113
+ ```
114
+ (In this example you can see that the second journey is actually ending at Chatswood. I checked the raw API data and it does in fact have the last leg of the second journey as being at Chatswood but doesn't give any explanation as to why. Interesting.)
115
+
116
+ * due: the time (in minutes) before the journey starts
117
+ * origin_stop_id: the specific departure stop id
118
+ * origin_name: the name of the departure location
119
+ * departure_time: the departure time, in UTC
120
+ * destination_stop_id: the specific destination stop id
121
+ * destination_name: the name of the destination location
122
+ * arrival_time: the planned arrival time at the origin, in UTC
123
+ * origin_transport_type: the type of transport, eg train, bus, ferry etc
124
+ * origin_transport_name: the full name of the transport provider
125
+ * origin_line_name & origin_line_name_short: the full and short names of the journey
126
+ * changes: how many transport changes are needed on the journey
127
+ * occupancy: how full the vehicle is, if available
128
+ * real_time_trip_id: the unique TransportNSW id for that specific journey, if available
129
+ * latitude & longitude: The location of the vehicle, if available
130
+ * alerts: An array of alerts pertinent to that journey
131
+
132
+
133
+ ### Notes ###
134
+ Requesting multiple journeys to be returned doesn't always return that exact number of journeys. The API only ever returns five or six, and if you have any filters applied then that might further reduce the number of 'valid' journeys.
135
+
136
+ ```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.
137
+
138
+ Note also that the origin and destination details are 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.
139
+
140
+ 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.
141
+
142
+ ## Thank you
143
+ 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!
144
+ https://github.com/Dav0815/TransportNSW
@@ -32,6 +32,8 @@ ATTR_REAL_TIME_TRIP_ID = 'real_time_trip_id'
32
32
  ATTR_LATITUDE = 'latitude'
33
33
  ATTR_LONGITUDE = 'longitude'
34
34
 
35
+ ATTR_ALERTS = 'alerts'
36
+
35
37
  logger = logging.getLogger(__name__)
36
38
 
37
39
  class TransportNSWv2(object):
@@ -67,11 +69,13 @@ class TransportNSWv2(object):
67
69
  ATTR_OCCUPANCY : 'n/a',
68
70
  ATTR_REAL_TIME_TRIP_ID : 'n/a',
69
71
  ATTR_LATITUDE : 'n/a',
70
- ATTR_LONGITUDE : 'n/a'
72
+ ATTR_LONGITUDE : 'n/a',
73
+ ATTR_ALERTS: '[]'
71
74
  }
72
75
 
73
76
  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, route_filter = ''):
77
+ strict_transport_type = False, raw_output = False, journeys_to_return = 1, route_filter = '', include_realtime_location = True, include_alerts = 'none', alert_type = 'all'):
78
+ # or 'lineInfo|stopInfo' etc as a list
75
79
  """Get the latest data from Transport NSW."""
76
80
  fmt = '%Y-%m-%dT%H:%M:%SZ'
77
81
 
@@ -84,6 +88,9 @@ class TransportNSWv2(object):
84
88
  self.raw_output = raw_output
85
89
  self.journeys_to_return = journeys_to_return
86
90
  self.route_filter = route_filter.lower()
91
+ self.include_realtime_location = include_realtime_location
92
+ self.include_alerts = include_alerts.lower()
93
+ self.alert_type = alert_type.lower()
87
94
 
88
95
  # This query always uses the current date and time - but add in any 'journey_wait_time' minutes
89
96
  now_plus_wait = datetime.now() + timedelta(minutes = journey_wait_time)
@@ -110,15 +117,15 @@ class TransportNSWv2(object):
110
117
  # Send the query and return an error if something goes wrong
111
118
  # Otherwise store the response
112
119
  try:
113
- response = requests.get(url, headers=header, timeout=10)
120
+ response = requests.get(url, headers=header, timeout=20)
114
121
  except:
115
122
  logger.warning("Network or Timeout error")
116
- return error_return(self.info, raw_output)
123
+ return None
117
124
 
118
125
  # If we get bad status code, log error and return with n/a or an empty string
119
126
  if response.status_code != 200:
120
127
  logger.warning("Error with the request sent; check api key")
121
- return error_return(self.info, raw_output)
128
+ return None
122
129
 
123
130
  # Parse the result as a JSON object
124
131
  result = response.json()
@@ -199,12 +206,17 @@ class TransportNSWv2(object):
199
206
  if 'occupancy' in first_stop['properties']:
200
207
  occupancy = first_stop['properties']['occupancy']
201
208
 
202
- # Now might be a good time to see if we can also find the latitude and longitude
203
- # Using the Realtime Vehicle Positions API
209
+ alerts = "[]"
210
+ if (include_alerts != 'none'):
211
+ # We'll be adding these to the returned JSON string as an array
212
+ # Only include alerts of the specified priority or greater, and of the specified type
213
+ alerts = self.find_alerts(legs, self.include_alerts, self.alert_type)
214
+
204
215
  latitude = 'n/a'
205
216
  longitude = 'n/a'
206
217
 
207
- if realtimetripid != 'n/a':
218
+ if ((realtimetripid != 'n/a') and (self.include_realtime_location) == True):
219
+ # See if we can get the latitute and longitude via the Realtime Vehicle Positions API
208
220
  # Build the URL(s) - some modes have multiple GTFS sources, unforunately
209
221
  url_path = self.get_url(origin_mode)
210
222
  url_list = self.get_url_path(origin_mode)
@@ -256,7 +268,8 @@ class TransportNSWv2(object):
256
268
  ATTR_OCCUPANCY : occupancy,
257
269
  ATTR_REAL_TIME_TRIP_ID : realtimetripid,
258
270
  ATTR_LATITUDE : latitude,
259
- ATTR_LONGITUDE : longitude
271
+ ATTR_LONGITUDE : longitude,
272
+ ATTR_ALERTS: json.loads(alerts)
260
273
  }
261
274
 
262
275
  found_journeys = found_journeys + 1
@@ -276,7 +289,7 @@ class TransportNSWv2(object):
276
289
  current_journey_index = next_journey_index
277
290
 
278
291
  json_output='{"journeys_to_return": ' + str(self.journeys_to_return) + ', "journeys_with_data": ' + str(found_journeys) + ', "journeys": [' + json_output + ']}'
279
- return json_output
292
+ return json.dumps(json_output)
280
293
 
281
294
 
282
295
  # def find_first_journey(self, journeys, journeytype, strictness):
@@ -376,19 +389,56 @@ class TransportNSWv2(object):
376
389
  return changes - 1
377
390
 
378
391
 
392
+ def find_alerts(self, legs, priority_filter, alert_type):
393
+ # Return an array of all the alerts on this trip that meet the priority level and alert type
394
+ leg_count = len(legs)
395
+ found_alerts = []
396
+ priority_minimum = self.get_alert_priority(priority_filter)
397
+ alert_list = alert_type.split("|")
398
+
399
+ for leg_index in range (0, leg_count, 1):
400
+ current_leg = legs[leg_index]
401
+ if 'infos' in current_leg:
402
+ alerts = current_leg['infos']
403
+ for alert in alerts:
404
+ if (self.get_alert_priority(alert['priority'])) >= priority_minimum:
405
+ if (alert_type == 'all') or (alert['type'].lower() in alert_list):
406
+ found_alerts.append (alert)
407
+
408
+ return json.dumps(found_alerts)
409
+
410
+
411
+ def find_hints(self, legs, legtype, priority):
412
+ # Return an array of all the hints on this trip that meet the priority type
413
+ leg_count = len(legs)
414
+
415
+ for leg_index in range (0, leg_count, 1):
416
+ current_leg = legs[leg_index]
417
+ leg_class = current_leg['transportation']['product']['class']
418
+ if 'hints' in current_leg:
419
+ print ("")
420
+ print ("Found hint(s) for leg " + str(leg_index) )
421
+ hints = current_leg['hints']
422
+ for hint in hints:
423
+ print ("Hint:")
424
+ print (hint)
425
+ print (" ")
426
+
427
+
428
+
379
429
  def get_mode(self, iconId):
380
430
  """Map the iconId to a full text string"""
381
431
  modes = {
382
- 1: "Train",
383
- 2: "Metro",
384
- 4: "Light rail",
385
- 5: "Bus",
386
- 7: "Coach",
387
- 9: "Ferry",
388
- 11: "School bus",
389
- 99: "Walk",
390
- 100: "Walk",
391
- 107: "Cycle"
432
+ 1 : "Train",
433
+ 2 : "Metro",
434
+ 4 : "Light rail",
435
+ 5 : "Bus",
436
+ 7 : "Coach",
437
+ 9 : "Ferry",
438
+ 11 : "School bus",
439
+ 99 : "Walk",
440
+ 100 : "Walk",
441
+ 107 : "Cycle"
392
442
  }
393
443
  return modes.get(iconId, None)
394
444
 
@@ -398,19 +448,34 @@ class TransportNSWv2(object):
398
448
  v2_url = "https://api.transport.nsw.gov.au/v2/gtfs/vehiclepos"
399
449
 
400
450
  url_options = {
401
- "Train": v2_url,
402
- "Metro": v2_url,
403
- "Light rail": v1_url,
404
- "Bus": v1_url,
405
- "Coach": v1_url,
406
- "Ferry": v1_url,
407
- "School bus": v1_url
451
+ "Train" : v2_url,
452
+ "Metro" : v2_url,
453
+ "Light rail" : v1_url,
454
+ "Bus" : v1_url,
455
+ "Coach" : v1_url,
456
+ "Ferry" : v1_url,
457
+ "School bus" : v1_url
408
458
  }
409
459
  return url_options.get(mode, None)
410
460
 
411
461
 
462
+ def get_alert_priority(self, alert_priority):
463
+ """Map the alert priority to a number so we can filter later """
464
+
465
+ alert_priorities = {
466
+ "all" : 0,
467
+ "veryLow" : 1,
468
+ "low" : 2,
469
+ "normal" : 3,
470
+ "high" : 4,
471
+ "veryHigh" : 5
472
+ }
473
+ return alert_priorities.get(alert_priority, 99)
474
+
475
+
412
476
  def get_url_path(self, mode):
413
477
  """Map the journey mode to the proper modifier URL """
478
+ # There's probably a better way of mapping the bus route/stop/line number to the correct URL to call in the GTFS API, but as of now I don't know it... hence the brute force approach, although I hate the lack of elegance
414
479
  bus_list = ["/buses", "/regionbuses/centralwestandorana", "/regionbuses/centralwestandorana2", "/regionbuses/newenglandnorthwest", "/regionbuses/northcoast", "/regionbuses/northcoast2", "/regionbuses/northcoast3", "/regionbuses/riverinamurray", "/regionbuses/riverinamurray2", "/regionbuses/southeasttablelands", "/regionbuses/southeasttablelands2", "/regionbuses/sydneysurrounds", "/regionbuses/newcastlehunter", "/regionbuses/farwest"]
415
480
 
416
481
  url_options = {
@@ -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.6",
8
+ version="0.7.0",
9
9
  author="andystewart999",
10
10
  description="Get detailed per-trip transport information from TransportNSW",
11
11
  long_description=long_description,
@@ -1,95 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: PyTransportNSWv2
3
- Version: 0.6.6
4
- Summary: Get detailed per-trip transport information from TransportNSW
5
- Home-page: https://github.com/andystewart999/TransportNSW
6
- Author: andystewart999
7
- License: UNKNOWN
8
- Description: # TransportNSWv2
9
- Python lib to access Transport NSW information.
10
-
11
- ## How to Use
12
-
13
- ### Get an API Key
14
- 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:
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
-
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, 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
-
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
-
22
- ### API Documentation
23
- The source API details can be found here: https://opendata.transport.nsw.gov.au/sites/default/files/2023-08/Trip%20Planner%20API%20manual-opendataproduction%20v3.2.pdf
24
-
25
- ### Parameters
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], [route_filter = ''] )
28
- ```
29
-
30
- Transport types:
31
- ```
32
- 1: Train
33
- 2: Metro
34
- 4: Light rail
35
- 5: Bus
36
- 7: Coach
37
- 9: Ferry
38
- 11: School bus
39
- 99: Walk
40
- 100: Walk
41
- 107: Cycle
42
- ```
43
-
44
- 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.
45
-
46
- ### Sample Code
47
-
48
- 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):
49
-
50
- **Code:**
51
- ```python
52
- from TransportNSWv2 import TransportNSWv2
53
- tnsw = TransportNSWv2()
54
- journey = tnsw.get_trip('207537', '10101100', 'YOUR_API_KEY', 5)
55
- print(journey)
56
- ```
57
- **Result:**
58
- ```python
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
- ```
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
-
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.
65
-
66
- * due: the time (in minutes) before the journey starts
67
- * origin_stop_id: the specific departure stop id
68
- * origin_name: the name of the departure location
69
- * departure_time: the departure time, in UTC
70
- * destination_stop_id: the specific destination stop id
71
- * destination_name: the name of the destination location
72
- * arrival_time: the planned arrival time at the origin, in UTC
73
- * origin_transport_type: the type of transport, eg train, bus, ferry etc
74
- * origin_transport_name: the full name of the transport provider
75
- * origin_line_name & origin_line_name_short: the full and short names of the journey
76
- * changes: how many transport changes are needed on the journey
77
- * occupancy: how full the vehicle is, if available
78
- * real_time_trip_id: the unique TransportNSW id for that specific journey, if available
79
- * latitude & longitude: The location of the vehicle, if available
80
-
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.
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.
84
-
85
- ## Thank you
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!
87
- https://github.com/Dav0815/TransportNSW
88
-
89
- Platform: UNKNOWN
90
- Classifier: Programming Language :: Python :: 3
91
- Classifier: License :: OSI Approved :: MIT License
92
- Classifier: Operating System :: OS Independent
93
- Classifier: Intended Audience :: Developers
94
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
95
- Description-Content-Type: text/markdown
@@ -1,95 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: PyTransportNSWv2
3
- Version: 0.6.6
4
- Summary: Get detailed per-trip transport information from TransportNSW
5
- Home-page: https://github.com/andystewart999/TransportNSW
6
- Author: andystewart999
7
- License: UNKNOWN
8
- Description: # TransportNSWv2
9
- Python lib to access Transport NSW information.
10
-
11
- ## How to Use
12
-
13
- ### Get an API Key
14
- 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:
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
-
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, 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
-
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
-
22
- ### API Documentation
23
- The source API details can be found here: https://opendata.transport.nsw.gov.au/sites/default/files/2023-08/Trip%20Planner%20API%20manual-opendataproduction%20v3.2.pdf
24
-
25
- ### Parameters
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], [route_filter = ''] )
28
- ```
29
-
30
- Transport types:
31
- ```
32
- 1: Train
33
- 2: Metro
34
- 4: Light rail
35
- 5: Bus
36
- 7: Coach
37
- 9: Ferry
38
- 11: School bus
39
- 99: Walk
40
- 100: Walk
41
- 107: Cycle
42
- ```
43
-
44
- 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.
45
-
46
- ### Sample Code
47
-
48
- 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):
49
-
50
- **Code:**
51
- ```python
52
- from TransportNSWv2 import TransportNSWv2
53
- tnsw = TransportNSWv2()
54
- journey = tnsw.get_trip('207537', '10101100', 'YOUR_API_KEY', 5)
55
- print(journey)
56
- ```
57
- **Result:**
58
- ```python
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
- ```
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
-
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.
65
-
66
- * due: the time (in minutes) before the journey starts
67
- * origin_stop_id: the specific departure stop id
68
- * origin_name: the name of the departure location
69
- * departure_time: the departure time, in UTC
70
- * destination_stop_id: the specific destination stop id
71
- * destination_name: the name of the destination location
72
- * arrival_time: the planned arrival time at the origin, in UTC
73
- * origin_transport_type: the type of transport, eg train, bus, ferry etc
74
- * origin_transport_name: the full name of the transport provider
75
- * origin_line_name & origin_line_name_short: the full and short names of the journey
76
- * changes: how many transport changes are needed on the journey
77
- * occupancy: how full the vehicle is, if available
78
- * real_time_trip_id: the unique TransportNSW id for that specific journey, if available
79
- * latitude & longitude: The location of the vehicle, if available
80
-
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.
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.
84
-
85
- ## Thank you
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!
87
- https://github.com/Dav0815/TransportNSW
88
-
89
- Platform: UNKNOWN
90
- Classifier: Programming Language :: Python :: 3
91
- Classifier: License :: OSI Approved :: MIT License
92
- Classifier: Operating System :: OS Independent
93
- Classifier: Intended Audience :: Developers
94
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
95
- Description-Content-Type: text/markdown
@@ -1,80 +0,0 @@
1
- # TransportNSWv2
2
- Python lib to access Transport NSW information.
3
-
4
- ## How to Use
5
-
6
- ### Get an API Key
7
- 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:
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
-
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, 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
-
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
-
15
- ### API Documentation
16
- The source API details can be found here: https://opendata.transport.nsw.gov.au/sites/default/files/2023-08/Trip%20Planner%20API%20manual-opendataproduction%20v3.2.pdf
17
-
18
- ### Parameters
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], [route_filter = ''] )
21
- ```
22
-
23
- Transport types:
24
- ```
25
- 1: Train
26
- 2: Metro
27
- 4: Light rail
28
- 5: Bus
29
- 7: Coach
30
- 9: Ferry
31
- 11: School bus
32
- 99: Walk
33
- 100: Walk
34
- 107: Cycle
35
- ```
36
-
37
- 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.
38
-
39
- ### Sample Code
40
-
41
- 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
- **Code:**
44
- ```python
45
- from TransportNSWv2 import TransportNSWv2
46
- tnsw = TransportNSWv2()
47
- journey = tnsw.get_trip('207537', '10101100', 'YOUR_API_KEY', 5)
48
- print(journey)
49
- ```
50
- **Result:**
51
- ```python
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
- ```
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
-
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.
58
-
59
- * due: the time (in minutes) before the journey starts
60
- * origin_stop_id: the specific departure stop id
61
- * origin_name: the name of the departure location
62
- * departure_time: the departure time, in UTC
63
- * destination_stop_id: the specific destination stop id
64
- * destination_name: the name of the destination location
65
- * arrival_time: the planned arrival time at the origin, in UTC
66
- * origin_transport_type: the type of transport, eg train, bus, ferry etc
67
- * origin_transport_name: the full name of the transport provider
68
- * origin_line_name & origin_line_name_short: the full and short names of the journey
69
- * changes: how many transport changes are needed on the journey
70
- * occupancy: how full the vehicle is, if available
71
- * real_time_trip_id: the unique TransportNSW id for that specific journey, if available
72
- * latitude & longitude: The location of the vehicle, if available
73
-
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.
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.
77
-
78
- ## Thank you
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!
80
- https://github.com/Dav0815/TransportNSW