PyTransportNSWv2 0.8.3__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,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 0.8.3
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
7
+ Author-email: andy.stewart@live.com
7
8
  License: UNKNOWN
8
9
  Description: # TransportNSWv2
9
10
  Python lib to access Transport NSW information.
@@ -147,7 +148,7 @@ Description: # TransportNSWv2
147
148
  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
 
149
150
  ### Rate limits ###
150
- By default the TransportNSW API allows each API key to make 60,000 calls in a day and up to 5 calls per second. Usually this wouldn't be an issue but due if you're requesting real-time location data for buses, because I haven't found an elegant way to map the bus route to the correct API URL (and there are about 14) it's brute-forcing it by iterating through ALL the possible URLs until it finds the appropriate journey or it runs out of URLs. From version 0.8.2 I've added in a 0.5 second delay between loops until I can find a better approach.
151
+ By default the TransportNSW API allows each API key to make 60,000 calls in a day and up to 5 calls per second. Usually this wouldn't be an issue but if you're requesting real-time location data for buses, because I haven't found an elegant way to map the bus route to the correct API URL (and there are about 14) it's brute-forcing it by iterating through ALL the possible URLs until it finds the appropriate journey or it runs out of URLs. From version 0.8.2 I've added in a 0.5 second delay between loops until I can find a better approach.
151
152
 
152
153
  ## Thank you
153
154
  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,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 0.8.3
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
7
+ Author-email: andy.stewart@live.com
7
8
  License: UNKNOWN
8
9
  Description: # TransportNSWv2
9
10
  Python lib to access Transport NSW information.
@@ -147,7 +148,7 @@ Description: # TransportNSWv2
147
148
  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
 
149
150
  ### Rate limits ###
150
- By default the TransportNSW API allows each API key to make 60,000 calls in a day and up to 5 calls per second. Usually this wouldn't be an issue but due if you're requesting real-time location data for buses, because I haven't found an elegant way to map the bus route to the correct API URL (and there are about 14) it's brute-forcing it by iterating through ALL the possible URLs until it finds the appropriate journey or it runs out of URLs. From version 0.8.2 I've added in a 0.5 second delay between loops until I can find a better approach.
151
+ By default the TransportNSW API allows each API key to make 60,000 calls in a day and up to 5 calls per second. Usually this wouldn't be an issue but if you're requesting real-time location data for buses, because I haven't found an elegant way to map the bus route to the correct API URL (and there are about 14) it's brute-forcing it by iterating through ALL the possible URLs until it finds the appropriate journey or it runs out of URLs. From version 0.8.2 I've added in a 0.5 second delay between loops until I can find a better approach.
151
152
 
152
153
  ## Thank you
153
154
  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!
@@ -140,7 +140,7 @@ Note also that the origin and destination details are just that - information ab
140
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
141
 
142
142
  ### Rate limits ###
143
- By default the TransportNSW API allows each API key to make 60,000 calls in a day and up to 5 calls per second. Usually this wouldn't be an issue but due if you're requesting real-time location data for buses, because I haven't found an elegant way to map the bus route to the correct API URL (and there are about 14) it's brute-forcing it by iterating through ALL the possible URLs until it finds the appropriate journey or it runs out of URLs. From version 0.8.2 I've added in a 0.5 second delay between loops until I can find a better approach.
143
+ By default the TransportNSW API allows each API key to make 60,000 calls in a day and up to 5 calls per second. Usually this wouldn't be an issue but if you're requesting real-time location data for buses, because I haven't found an elegant way to map the bus route to the correct API URL (and there are about 14) it's brute-forcing it by iterating through ALL the possible URLs until it finds the appropriate journey or it runs out of URLs. From version 0.8.2 I've added in a 0.5 second delay between loops until I can find a better approach.
144
144
 
145
145
  ## Thank you
146
146
  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,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,9 +120,13 @@ 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
- logger.error("Error " + str(response.status_code) + " calling /v1/tp/stop_finder API; check api key")
125
+ if response.status_code == 429:
126
+ logger.error("Error " + str(response.status_code) + " calling /v1/tp/stop_finder API; rate limit exceeded")
127
+ else:
128
+ logger.error("Error " + str(response.status_code) + " calling /v1/tp/stop_finder API; check api key")
129
+
125
130
  return None
126
131
 
127
132
  # Parse the result as a JSON object
@@ -131,9 +136,9 @@ class TransportNSWv2(object):
131
136
  if 'systemMessages' in result:
132
137
  logger.error("Stop ID " + stop + " does not exist")
133
138
 
134
- # 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
135
140
  # Not usually an issue but if multiple processes are running multiple calls we might hit it
136
- time.sleep(0.5)
141
+ time.sleep(1.0)
137
142
 
138
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
139
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
@@ -154,13 +159,17 @@ class TransportNSWv2(object):
154
159
  try:
155
160
  response = requests.get(url, headers=header, timeout=20)
156
161
  except:
157
- logger.error("Network or Timeout error")
162
+ logger.error("Network or timeout error")
158
163
  return None
159
164
 
160
165
  # If we get bad status code, log error and return with n/a or an empty string
161
166
  if response.status_code != 200:
162
- logger.error("Error " + str(response.status_code) + " calling /v1/tp/trip API; check api key")
163
- 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
164
173
 
165
174
  # Parse the result as a JSON object
166
175
  result = response.json()
@@ -190,7 +199,6 @@ class TransportNSWv2(object):
190
199
  if ((journey is None) or (journey['legs']) is None):
191
200
  pass
192
201
  else:
193
- print (journey)
194
202
  legs = journey['legs']
195
203
  first_leg = self.find_first_leg(legs, transport_type, strict_transport_type, route_filter)
196
204
 
@@ -213,8 +221,6 @@ class TransportNSWv2(object):
213
221
  t2 = datetime.strptime(origin_departure_time_planned, fmt).timestamp()
214
222
  delay = int((t1-t2) / 60)
215
223
 
216
- #print (origin_departure_time - origin_departure_time_planned)
217
-
218
224
  # How long until it leaves?
219
225
  due = self.get_due(datetime.strptime(origin_departure_time, fmt))
220
226
 
@@ -265,10 +271,11 @@ class TransportNSWv2(object):
265
271
  url_list = self.get_url_path(origin_mode)
266
272
  bFoundTripID = False
267
273
 
274
+ auth = 'apikey ' + self.api_key
275
+ header = {'Authorization': auth}
276
+
268
277
  for mode_url in url_list:
269
278
  url = url_path + mode_url
270
- auth = 'apikey ' + self.api_key
271
- header = {'Authorization': auth}
272
279
 
273
280
  response = requests.get(url, headers=header, timeout=10)
274
281
 
@@ -294,14 +301,11 @@ class TransportNSWv2(object):
294
301
  # No need to look any further
295
302
  break
296
303
 
297
-
298
- # 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
299
305
  # Not usually an issue but if multiple processes are running multiple calls we might hit it
300
306
  time.sleep(0.5)
301
307
 
302
308
 
303
-
304
-
305
309
  self.info = {
306
310
  ATTR_DUE_IN: due,
307
311
  ATTR_DELAY: delay,
@@ -445,17 +449,13 @@ class TransportNSWv2(object):
445
449
  leg_count = len(legs)
446
450
  found_alerts = []
447
451
  priority_minimum = self.get_alert_priority(priority_filter)
448
- print ("priority_minimum = " + str(priority_minimum))
449
452
  alert_list = alert_type.split("|")
450
453
 
451
454
  for leg_index in range (0, leg_count, 1):
452
455
  current_leg = legs[leg_index]
453
456
  if 'infos' in current_leg:
454
- print ("Found 'infos' in leg")
455
- print (current_leg['infos'])
456
457
  alerts = current_leg['infos']
457
458
  for alert in alerts:
458
- print ("Found alert")
459
459
  if (self.get_alert_priority(alert['priority'])) >= priority_minimum:
460
460
  if (alert_type == 'all') or (alert['type'].lower() in alert_list):
461
461
  found_alerts.append (alert)
@@ -471,14 +471,7 @@ class TransportNSWv2(object):
471
471
  current_leg = legs[leg_index]
472
472
  leg_class = current_leg['transportation']['product']['class']
473
473
  if 'hints' in current_leg:
474
- #print ("")
475
- #print ("Found hint(s) for leg " + str(leg_index) )
476
474
  hints = current_leg['hints']
477
- #for hint in hints:
478
- #print ("Hint:")
479
- #print (hint)
480
- #print (" ")
481
-
482
475
 
483
476
 
484
477
  def get_mode(self, iconId):
@@ -5,8 +5,9 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="PyTransportNSWv2",
8
- version="0.8.3",
8
+ version="0.8.5",
9
9
  author="andystewart999",
10
+ author_email="andy.stewart@live.com",
10
11
  description="Get detailed per-trip transport information from TransportNSW",
11
12
  long_description=long_description,
12
13
  long_description_content_type="text/markdown",