PyTransportNSWv2 0.8.4__tar.gz → 0.8.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 0.8.4
3
+ Version: 0.8.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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 0.8.4
3
+ Version: 0.8.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
@@ -8,8 +8,9 @@ import requests.exceptions
8
8
  import requests
9
9
  import logging
10
10
  import re
11
- import json #For the output
11
+ import json #For the output
12
12
  import time
13
+ #from ratelimit import limits, sleep_and_retry # API rate limiting
13
14
 
14
15
  ATTR_DUE_IN = 'due'
15
16
 
@@ -119,7 +120,7 @@ class TransportNSWv2(object):
119
120
  logger.error("Network or Timeout error when calling /v1/tp/stop_finder API")
120
121
  return None
121
122
 
122
- # If we get bad status code, log error and return with n/a or an empty string
123
+ # If we get bad status code, log error and return with None
123
124
  if response.status_code != 200:
124
125
  if response.status_code == 429:
125
126
  logger.error("Error " + str(response.status_code) + " calling /v1/tp/stop_finder API; rate limit exceeded")
@@ -135,9 +136,9 @@ class TransportNSWv2(object):
135
136
  if 'systemMessages' in result:
136
137
  logger.error("Stop ID " + stop + " does not exist")
137
138
 
138
- # Put in a quick pause here to try and make sure we stay under the 5 minute calls/second limit
139
+ # Put in a pause here to try and make sure we stay under the 5 API calls/second limit
139
140
  # Not usually an issue but if multiple processes are running multiple calls we might hit it
140
- time.sleep(0.5)
141
+ time.sleep(1.0)
141
142
 
142
143
  # We don't control how many journeys are returned any more, so need to be careful of running out of valid journeys if there is a filter in place, particularly a strict filter
143
144
  # It would be more efficient to return one journey, check if the filter is met and then retrieve the next one via a new query if not, but for now we'll only be making use of the journeys we've been given
@@ -158,13 +159,17 @@ class TransportNSWv2(object):
158
159
  try:
159
160
  response = requests.get(url, headers=header, timeout=20)
160
161
  except:
161
- logger.error("Network or Timeout error")
162
+ logger.error("Network or timeout error")
162
163
  return None
163
164
 
164
165
  # If we get bad status code, log error and return with n/a or an empty string
165
166
  if response.status_code != 200:
166
- logger.error("Error " + str(response.status_code) + " calling /v1/tp/trip API; check api key")
167
- return None
167
+ if response.status_code == 429:
168
+ logger.error("Error " + str(response.status_code) + " calling /v1/tp/stop_finder API; rate limit exceeded")
169
+ else:
170
+ logger.error("Error " + str(response.status_code) + " calling /v1/tp/stop_finder API; check api key")
171
+
172
+ return None
168
173
 
169
174
  # Parse the result as a JSON object
170
175
  result = response.json()
@@ -266,10 +271,11 @@ class TransportNSWv2(object):
266
271
  url_list = self.get_url_path(origin_mode)
267
272
  bFoundTripID = False
268
273
 
274
+ auth = 'apikey ' + self.api_key
275
+ header = {'Authorization': auth}
276
+
269
277
  for mode_url in url_list:
270
278
  url = url_path + mode_url
271
- auth = 'apikey ' + self.api_key
272
- header = {'Authorization': auth}
273
279
 
274
280
  response = requests.get(url, headers=header, timeout=10)
275
281
 
@@ -295,14 +301,11 @@ class TransportNSWv2(object):
295
301
  # No need to look any further
296
302
  break
297
303
 
298
-
299
- # Put in a quick pause here to try and make sure we stay under the 5 minute calls/second limit
304
+ # Put in a quick pause here to try and make sure we stay under the 5 API calls/second limit
300
305
  # Not usually an issue but if multiple processes are running multiple calls we might hit it
301
306
  time.sleep(0.5)
302
307
 
303
308
 
304
-
305
-
306
309
  self.info = {
307
310
  ATTR_DUE_IN: due,
308
311
  ATTR_DELAY: delay,
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="PyTransportNSWv2",
8
- version="0.8.4",
8
+ version="0.8.5",
9
9
  author="andystewart999",
10
10
  author_email="andy.stewart@live.com",
11
11
  description="Get detailed per-trip transport information from TransportNSW",