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