PyTransportNSWv2 2.0.2__tar.gz → 2.0.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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 2.0.2
3
+ Version: 2.0.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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 2.0.2
3
+ Version: 2.0.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
@@ -198,6 +198,7 @@ class TransportNSWv2(object):
198
198
 
199
199
  """Get the latest data from Transport NSW."""
200
200
  fmt = '%Y-%m-%dT%H:%M:%SZ'
201
+ api_calls = 0
201
202
 
202
203
  route_filter = route_filter.lower()
203
204
  include_alerts = include_alerts.lower()
@@ -269,7 +270,7 @@ class TransportNSWv2(object):
269
270
  raise APIRateLimitExceeded("Error 'API rate limit exceeded' calling trip API for journey {name_origin} to {name_destination}")
270
271
 
271
272
  else:
272
- raise TripError(f"Error '{str(response.status_cude)}' calling trip API for journey {name_origin} to {name_destination}")
273
+ raise TripError(f"Error '{str(response.status_code)}' calling trip API for journey {name_origin} to {name_destination}")
273
274
 
274
275
  result = response.json()
275
276
 
@@ -452,14 +453,16 @@ class TransportNSWv2(object):
452
453
  return None, None, None, None, None
453
454
 
454
455
  for journey_index in range (start_journey_index, journey_count, 1):
455
- origin_leg = self._find_first_leg(journeys[journey_index]['legs'], origin_transport_type, strict, route_filter)
456
+ journey = journeys[journey_index]
457
+
458
+ origin_leg = self._find_first_leg(journey['legs'], origin_transport_type, strict, route_filter)
456
459
 
457
460
  if origin_leg is not None:
458
- destination_leg = self._find_last_leg(journeys[journey_index]['legs'], destination_transport_type, strict)
461
+ destination_leg = self._find_last_leg(journey['legs'], destination_transport_type, strict)
459
462
 
460
463
  if origin_leg is not None and destination_leg is not None:
461
- changes = self._find_changes(journeys[journey_index]['legs'], origin_leg, destination_leg)
462
- return journeys[journey_index]['legs'], journey_index + 1, origin_leg, destination_leg, changes
464
+ changes = self._find_changes(journey['legs'], origin_leg, destination_leg)
465
+ return journey['legs'], journey_index + 1, origin_leg, destination_leg, changes
463
466
  else:
464
467
  return None, None, None, None, None
465
468
 
@@ -523,24 +526,28 @@ class TransportNSWv2(object):
523
526
 
524
527
 
525
528
  def _find_changes(self, legs, origin_leg, destination_leg):
526
- # Find out how often we have to change
529
+ # Find out how often we have to change. Immediately return 0 if the origin and destination legs are the same
530
+ if origin_leg == destination_leg:
531
+ return 0
532
+
533
+ # Count the changes, each time we hit new non-walking leg is considered to be a change
527
534
  changes = 0
528
535
  bInJourney = False
529
536
 
530
537
  for leg in legs:
531
- if leg == destination_leg:
532
- # We've found the last leg (which oould be the same as the first leg), stop counting
533
- return changes
534
-
535
538
  if leg == origin_leg:
536
- # We've found the first leg, start counting
539
+ # We're in the journey so start capturing changes
537
540
  bInJourney = True
538
- else:
539
- if bInJourney:
540
- leg_class = leg['transportation']['product']['class']
541
- if leg_class < 99:
541
+
542
+ elif bInJourney:
543
+ leg_class = leg['transportation']['product']['class']
544
+ if leg_class < 99:
545
+ if leg != destination_leg:
542
546
  changes += 1
543
547
 
548
+ if leg == destination_leg:
549
+ return changes
550
+
544
551
  # We should never get here!
545
552
  return 999
546
553
 
@@ -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.2",
8
+ version="2.0.4",
9
9
  author="andystewart999",
10
10
  author_email="andy.stewart@live.com",
11
11
  description="Get detailed per-trip transport information from TransportNSW",