PyTransportNSWv2 2.0.1__tar.gz → 2.0.2__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: 2.0.1
3
+ Version: 2.0.2
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: 2.0.1
3
+ Version: 2.0.2
4
4
  Summary: Get detailed per-trip transport information from TransportNSW
5
5
  Home-page: https://github.com/andystewart999/TransportNSW
6
6
  Author: andystewart999
@@ -12,6 +12,15 @@ import re
12
12
  import json #For the output
13
13
  import time
14
14
 
15
+ # Global API variable
16
+ api_calls = 0
17
+
18
+ def increment_api_counter(source):
19
+ global api_calls
20
+ api_calls += 1
21
+ #print(str(api_calls) + " " + source)
22
+
23
+ # Constants
15
24
  ATTR_DUE_IN = 'due'
16
25
 
17
26
  ATTR_ORIGIN_STOP_ID = 'origin_stop_id'
@@ -117,7 +126,10 @@ class TransportNSWv2(object):
117
126
  error_code = 0
118
127
 
119
128
  if not skip_api_calls:
129
+ # Make the call and increment the API counter
120
130
  response = requests.get(url, headers=header, timeout=5)
131
+ increment_api_counter('stop_finder')
132
+
121
133
  else:
122
134
  # An earlier call resulted in an API key error so no point trying again
123
135
  response.status_code = 401
@@ -195,7 +207,7 @@ class TransportNSWv2(object):
195
207
  origin_transport_type = [origin_transport_type]
196
208
 
197
209
  if isinstance(destination_transport_type, int):
198
- destiation_transport_type = [destination_transport_type]
210
+ destination_transport_type = [destination_transport_type]
199
211
 
200
212
  if isinstance(alert_type, str):
201
213
  alert_type = alert_type.split('|')
@@ -242,6 +254,7 @@ class TransportNSWv2(object):
242
254
  # Otherwise store the response for the next steps
243
255
  try:
244
256
  response = requests.get(url, headers=header, timeout=10)
257
+ increment_api_counter('trip')
245
258
 
246
259
  except Exception as ex:
247
260
  raise TripError (f"Error '{str(ex)}' calling trip API for journey {name_origin} to {name_destination}")
@@ -426,7 +439,7 @@ class TransportNSWv2(object):
426
439
 
427
440
  current_journey_index = next_journey_index
428
441
 
429
- json_output='{"journeys_to_return": ' + str(journeys_to_return) + ', "journeys_with_data": ' + str(found_journeys) + ', "journeys": [' + json_output + ']}'
442
+ json_output='{"journeys_to_return": ' + str(journeys_to_return) + ', "journeys_with_data": ' + str(found_journeys) + ', "api_calls": ' + str(api_calls) + ', "journeys": [' + json_output + ']}'
430
443
  return json_output
431
444
 
432
445
 
@@ -559,12 +572,14 @@ class TransportNSWv2(object):
559
572
  header = {'Accept': 'application/json', 'Authorization': auth}
560
573
 
561
574
  url_base_path = self._get_base_url(mode)
562
-
563
575
  url_mode_list = self._get_mode_list(mode, agencyid)
576
+
564
577
  if not url_mode_list is None:
565
578
  for mode_url in url_mode_list:
566
579
  url = url_base_path + mode_url
567
580
  response = requests.get(url, headers=header, timeout=10)
581
+ increment_api_counter(url)
582
+
568
583
  # Only try and process the results if we got a good return code
569
584
  if response.status_code == 200:
570
585
  # Search the feed and see if we can match realtimetripid to trip_id
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="PyTransportNSWv2",
8
- version="2.0.1",
8
+ version="2.0.2",
9
9
  author="andystewart999",
10
10
  author_email="andy.stewart@live.com",
11
11
  description="Get detailed per-trip transport information from TransportNSW",