PyTransportNSWv2 0.8.2__tar.gz → 0.8.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,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 0.8.2
3
+ Version: 0.8.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
7
+ Author-email: andy.stewart@live.com
7
8
  License: UNKNOWN
8
9
  Description: # TransportNSWv2
9
10
  Python lib to access Transport NSW information.
@@ -146,6 +147,9 @@ Description: # TransportNSWv2
146
147
 
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
 
150
+ ### Rate limits ###
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.
152
+
149
153
  ## Thank you
150
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!
151
155
  https://github.com/Dav0815/TransportNSW
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 0.8.2
3
+ Version: 0.8.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
7
+ Author-email: andy.stewart@live.com
7
8
  License: UNKNOWN
8
9
  Description: # TransportNSWv2
9
10
  Python lib to access Transport NSW information.
@@ -146,6 +147,9 @@ Description: # TransportNSWv2
146
147
 
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
 
150
+ ### Rate limits ###
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.
152
+
149
153
  ## Thank you
150
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!
151
155
  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 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,11 @@ 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
+ if response.status_code == 429:
125
+ logger.error("Error " + str(response.status_code) + " calling /v1/tp/stop_finder API; rate limit exceeded")
126
+ else:
127
+ logger.error("Error " + str(response.status_code) + " calling /v1/tp/stop_finder API; check api key")
128
+
124
129
  return None
125
130
 
126
131
  # Parse the result as a JSON object
@@ -130,6 +135,10 @@ class TransportNSWv2(object):
130
135
  if 'systemMessages' in result:
131
136
  logger.error("Stop ID " + stop + " does not exist")
132
137
 
138
+ # Put in a quick pause here to try and make sure we stay under the 5 minute calls/second limit
139
+ # Not usually an issue but if multiple processes are running multiple calls we might hit it
140
+ time.sleep(0.5)
141
+
133
142
  # 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
143
  # 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
144
 
@@ -154,7 +163,7 @@ class TransportNSWv2(object):
154
163
 
155
164
  # If we get bad status code, log error and return with n/a or an empty string
156
165
  if response.status_code != 200:
157
- logger.error("Error with the request sent; check api key")
166
+ logger.error("Error " + str(response.status_code) + " calling /v1/tp/trip API; check api key")
158
167
  return None
159
168
 
160
169
  # Parse the result as a JSON object
@@ -207,8 +216,6 @@ class TransportNSWv2(object):
207
216
  t2 = datetime.strptime(origin_departure_time_planned, fmt).timestamp()
208
217
  delay = int((t1-t2) / 60)
209
218
 
210
- #print (origin_departure_time - origin_departure_time_planned)
211
-
212
219
  # How long until it leaves?
213
220
  due = self.get_due(datetime.strptime(origin_departure_time, fmt))
214
221
 
@@ -289,6 +296,13 @@ class TransportNSWv2(object):
289
296
  break
290
297
 
291
298
 
299
+ # Put in a quick pause here to try and make sure we stay under the 5 minute calls/second limit
300
+ # Not usually an issue but if multiple processes are running multiple calls we might hit it
301
+ time.sleep(0.5)
302
+
303
+
304
+
305
+
292
306
  self.info = {
293
307
  ATTR_DUE_IN: due,
294
308
  ATTR_DELAY: delay,
@@ -454,14 +468,7 @@ class TransportNSWv2(object):
454
468
  current_leg = legs[leg_index]
455
469
  leg_class = current_leg['transportation']['product']['class']
456
470
  if 'hints' in current_leg:
457
- #print ("")
458
- #print ("Found hint(s) for leg " + str(leg_index) )
459
471
  hints = current_leg['hints']
460
- #for hint in hints:
461
- #print ("Hint:")
462
- #print (hint)
463
- #print (" ")
464
-
465
472
 
466
473
 
467
474
  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.2",
8
+ version="0.8.4",
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",