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.
- {PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/PKG-INFO +1 -1
- {PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/PyTransportNSWv2.egg-info/PKG-INFO +1 -1
- {PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/TransportNSWv2/TransportNSWv2.py +16 -13
- {PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/setup.py +1 -1
- {PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/LICENSE +0 -0
- {PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/PyTransportNSWv2.egg-info/SOURCES.txt +0 -0
- {PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/PyTransportNSWv2.egg-info/dependency_links.txt +0 -0
- {PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/PyTransportNSWv2.egg-info/requires.txt +0 -0
- {PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/PyTransportNSWv2.egg-info/top_level.txt +0 -0
- {PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/README.md +0 -0
- {PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/TransportNSWv2/__init__.py +0 -0
- {PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/setup.cfg +0 -0
@@ -8,8 +8,9 @@ import requests.exceptions
|
|
8
8
|
import requests
|
9
9
|
import logging
|
10
10
|
import re
|
11
|
-
import json
|
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
|
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
|
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
|
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
|
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
|
-
|
167
|
-
|
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.
|
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",
|
File without changes
|
File without changes
|
{PyTransportNSWv2-0.8.4 → PyTransportNSWv2-0.8.5}/PyTransportNSWv2.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|