PyTransportNSWv2 1.0.3__tar.gz → 1.0.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary: Get detailed per-trip transport information from TransportNSW
5
5
  Home-page: https://github.com/andystewart999/TransportNSW
6
6
  Author: andystewart999
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary: Get detailed per-trip transport information from TransportNSW
5
5
  Home-page: https://github.com/andystewart999/TransportNSW
6
6
  Author: andystewart999
@@ -88,15 +88,15 @@ class TransportNSWv2(object):
88
88
  stop_list = []
89
89
  skip_api_calls = False
90
90
 
91
- for stop in stops:
92
- url = \
93
- 'https://api.transport.nsw.gov.au/v1/tp/stop_finder?' \
94
- 'outputFormat=rapidJSON&coordOutputFormat=EPSG%3A4326' \
95
- '&type_sf=stop&name_sf=' + stop + \
96
- '&TfNSWSF=true'
97
-
98
- # Send the query
99
- try:
91
+ try:
92
+ for stop in stops:
93
+ url = \
94
+ 'https://api.transport.nsw.gov.au/v1/tp/stop_finder?' \
95
+ 'outputFormat=rapidJSON&coordOutputFormat=EPSG%3A4326' \
96
+ '&type_sf=stop&name_sf=' + stop + \
97
+ '&TfNSWSF=true'
98
+
99
+ # Send the query
100
100
  url = 'https://api.transport.nsw.gov.au/v1/tp/stop_finder?outputFormat=rapidJSON&coordOutputFormat=EPSG%3A4326&type_sf=stop&name_sf=' + stop + '&TfNSWSF=true'
101
101
  error_code = 0
102
102
 
@@ -124,7 +124,6 @@ class TransportNSWv2(object):
124
124
  else:
125
125
  # Parse the result as a JSON object
126
126
  stop_detail = response.json()
127
-
128
127
  # Just a quick check - the presence of systemMessages signifies an error, otherwise we assume it's ok
129
128
  if 'systemMessages' in stop_detail:
130
129
  error_text = stop_detail['systemMessages'][0]['text']
@@ -134,10 +133,6 @@ class TransportNSWv2(object):
134
133
  # Not usually an issue but if multiple processes are running multiple calls we might hit it
135
134
  time.sleep(1.0)
136
135
 
137
- except Exception as ex:
138
- raise StopError(f"Error '{ex}' calling stop finder API for stop ID {stop}", stop)
139
-
140
- finally:
141
136
  # Append the results to the JSON output - only return the 'isBest' location entry if there's more than one
142
137
  if stop_detail != []:
143
138
  stop_valid = True
@@ -154,10 +149,19 @@ class TransportNSWv2(object):
154
149
  data = {"stop_id": stop, "valid": stop_valid, "error_code": error_code, "stop_detail": stop_detail}
155
150
  stop_list.append (data)
156
151
 
157
- # Complete the JSON output and return it
158
- data = {"all_stops_valid": all_stops_valid, "stop_list": stop_list}
159
- #return json.dumps(data)
160
- return data
152
+ # Complete the JSON output and return it
153
+ data = {"all_stops_valid": all_stops_valid, "stop_list": stop_list}
154
+
155
+ return data
156
+
157
+ except InvalidAPIKey as ex:
158
+ raise InvalidAPIKey (f"Invalid API key {api_key}")
159
+
160
+ except StopError as ex:
161
+ raise StopError (f"Error '{ex}' calling stop finder API for stop ID {stop}")
162
+
163
+ except Exception as ex:
164
+ raise StopError(f"Error '{ex}' calling stop finder API for stop ID {stop}", stop)
161
165
 
162
166
 
163
167
  def get_trip(self, name_origin, name_destination , api_key, journey_wait_time = 0, transport_type = 0, \
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="PyTransportNSWv2",
8
- version="1.0.3",
8
+ version="1.0.4",
9
9
  author="andystewart999",
10
10
  author_email="andy.stewart@live.com",
11
11
  description="Get detailed per-trip transport information from TransportNSW",