PyTransportNSWv2 0.8.0__tar.gz → 0.8.3__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.0
3
+ Version: 0.8.3
4
4
  Summary: Get detailed per-trip transport information from TransportNSW
5
5
  Home-page: https://github.com/andystewart999/TransportNSW
6
6
  Author: andystewart999
@@ -146,6 +146,9 @@ Description: # TransportNSWv2
146
146
 
147
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
148
 
149
+ ### 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
+
149
152
  ## Thank you
150
153
  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
154
  https://github.com/Dav0815/TransportNSW
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 0.8.0
3
+ Version: 0.8.3
4
4
  Summary: Get detailed per-trip transport information from TransportNSW
5
5
  Home-page: https://github.com/andystewart999/TransportNSW
6
6
  Author: andystewart999
@@ -146,6 +146,9 @@ Description: # TransportNSWv2
146
146
 
147
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
148
 
149
+ ### 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
+
149
152
  ## Thank you
150
153
  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
154
  https://github.com/Dav0815/TransportNSW
@@ -139,6 +139,9 @@ Note also that the origin and destination details are just that - information ab
139
139
 
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
+ ### 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.
144
+
142
145
  ## Thank you
143
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!
144
147
  https://github.com/Dav0815/TransportNSW
@@ -9,6 +9,7 @@ import requests
9
9
  import logging
10
10
  import re
11
11
  import json #For the output
12
+ import time
12
13
 
13
14
  ATTR_DUE_IN = 'due'
14
15
 
@@ -120,7 +121,7 @@ class TransportNSWv2(object):
120
121
 
121
122
  # If we get bad status code, log error and return with n/a or an empty string
122
123
  if response.status_code != 200:
123
- logger.error("Error calling /v1/tp/stop_finder API; check api key")
124
+ logger.error("Error " + str(response.status_code) + " calling /v1/tp/stop_finder API; check api key")
124
125
  return None
125
126
 
126
127
  # Parse the result as a JSON object
@@ -130,6 +131,10 @@ class TransportNSWv2(object):
130
131
  if 'systemMessages' in result:
131
132
  logger.error("Stop ID " + stop + " does not exist")
132
133
 
134
+ # Put in a quick pause here to try and make sure we stay under the 5 minute calls/second limit
135
+ # Not usually an issue but if multiple processes are running multiple calls we might hit it
136
+ time.sleep(0.5)
137
+
133
138
  # 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
134
139
  # 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
135
140
 
@@ -154,7 +159,7 @@ class TransportNSWv2(object):
154
159
 
155
160
  # If we get bad status code, log error and return with n/a or an empty string
156
161
  if response.status_code != 200:
157
- logger.error("Error with the request sent; check api key")
162
+ logger.error("Error " + str(response.status_code) + " calling /v1/tp/trip API; check api key")
158
163
  return None
159
164
 
160
165
  # Parse the result as a JSON object
@@ -185,6 +190,7 @@ class TransportNSWv2(object):
185
190
  if ((journey is None) or (journey['legs']) is None):
186
191
  pass
187
192
  else:
193
+ print (journey)
188
194
  legs = journey['legs']
189
195
  first_leg = self.find_first_leg(legs, transport_type, strict_transport_type, route_filter)
190
196
 
@@ -289,6 +295,13 @@ class TransportNSWv2(object):
289
295
  break
290
296
 
291
297
 
298
+ # Put in a quick pause here to try and make sure we stay under the 5 minute calls/second limit
299
+ # Not usually an issue but if multiple processes are running multiple calls we might hit it
300
+ time.sleep(0.5)
301
+
302
+
303
+
304
+
292
305
  self.info = {
293
306
  ATTR_DUE_IN: due,
294
307
  ATTR_DELAY: delay,
@@ -432,13 +445,17 @@ class TransportNSWv2(object):
432
445
  leg_count = len(legs)
433
446
  found_alerts = []
434
447
  priority_minimum = self.get_alert_priority(priority_filter)
448
+ print ("priority_minimum = " + str(priority_minimum))
435
449
  alert_list = alert_type.split("|")
436
450
 
437
451
  for leg_index in range (0, leg_count, 1):
438
452
  current_leg = legs[leg_index]
439
453
  if 'infos' in current_leg:
454
+ print ("Found 'infos' in leg")
455
+ print (current_leg['infos'])
440
456
  alerts = current_leg['infos']
441
457
  for alert in alerts:
458
+ print ("Found alert")
442
459
  if (self.get_alert_priority(alert['priority'])) >= priority_minimum:
443
460
  if (alert_type == 'all') or (alert['type'].lower() in alert_list):
444
461
  found_alerts.append (alert)
@@ -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.0",
8
+ version="0.8.3",
9
9
  author="andystewart999",
10
10
  description="Get detailed per-trip transport information from TransportNSW",
11
11
  long_description=long_description,