PyTransportNSWv2 2.0.3__tar.gz → 2.0.5__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.3
3
+ Version: 2.0.5
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.3
3
+ Version: 2.0.5
4
4
  Summary: Get detailed per-trip transport information from TransportNSW
5
5
  Home-page: https://github.com/andystewart999/TransportNSW
6
6
  Author: andystewart999
@@ -42,6 +42,7 @@ ATTR_DESTINATION_LINE_NAME = 'destination_line_name'
42
42
  ATTR_DESTINATION_LINE_NAME_SHORT = 'destination_line_name_short'
43
43
 
44
44
  ATTR_CHANGES = 'changes'
45
+ ATTR_CHANGES_LIST = 'changes_list'
45
46
 
46
47
  ATTR_ORIGIN_OCCUPANCY = 'origin_occupancy'
47
48
  ATTR_DESTINATION_OCCUPANCY = 'destination_occupancy'
@@ -84,6 +85,7 @@ class TransportNSWv2(object):
84
85
  ATTR_DESTINATION_LINE_NAME : 'n/a',
85
86
  ATTR_DESTINATION_LINE_NAME_SHORT : 'n/a',
86
87
  ATTR_CHANGES : 'n/a',
88
+ ATTR_CHANGES_LIST: [],
87
89
  ATTR_ORIGIN_OCCUPANCY: 'n/a',
88
90
  ATTR_DESTINATION_OCCUPANCY: 'n/a',
89
91
  ATTR_ORIGIN_REAL_TIME_TRIP_ID : 'n/a',
@@ -198,6 +200,7 @@ class TransportNSWv2(object):
198
200
 
199
201
  """Get the latest data from Transport NSW."""
200
202
  fmt = '%Y-%m-%dT%H:%M:%SZ'
203
+ api_calls = 0
201
204
 
202
205
  route_filter = route_filter.lower()
203
206
  include_alerts = include_alerts.lower()
@@ -297,7 +300,7 @@ class TransportNSWv2(object):
297
300
 
298
301
  for current_journey_index in range (0, retrieved_journeys, 1):
299
302
  # Look for a trip with a matching transport type filter in at least one of its legs. Either ANY, or the first leg, depending on how strict we're being
300
- legs, next_journey_index, first_leg, last_leg, changes = self._find_next_journey(result['journeys'], current_journey_index, origin_transport_type, destination_transport_type, strict_transport_type, route_filter)
303
+ legs, next_journey_index, first_leg, last_leg, changes, changes_list = self._find_next_journey(result['journeys'], current_journey_index, origin_transport_type, destination_transport_type, strict_transport_type, route_filter)
301
304
 
302
305
  if legs is None:
303
306
  # An empty journey that didn't meet the criteria - which means all the valid journeys have been found already
@@ -412,6 +415,7 @@ class TransportNSWv2(object):
412
415
  ATTR_DESTINATION_LINE_NAME : destination_line_name,
413
416
  ATTR_DESTINATION_LINE_NAME_SHORT : destination_line_name_short,
414
417
  ATTR_CHANGES: changes,
418
+ ATTR_CHANGES_LIST: changes_list,
415
419
  ATTR_ORIGIN_OCCUPANCY: origin_occupancy,
416
420
  ATTR_DESTINATION_OCCUPANCY: destination_occupancy,
417
421
  ATTR_ORIGIN_REAL_TIME_TRIP_ID: origin_realtimetripid,
@@ -460,13 +464,13 @@ class TransportNSWv2(object):
460
464
  destination_leg = self._find_last_leg(journey['legs'], destination_transport_type, strict)
461
465
 
462
466
  if origin_leg is not None and destination_leg is not None:
463
- changes = self._find_changes(journey['legs'], origin_leg, destination_leg)
464
- return journey['legs'], journey_index + 1, origin_leg, destination_leg, changes
467
+ changes, changes_list = self._find_changes(journey['legs'], origin_leg, destination_leg)
468
+ return journey['legs'], journey_index + 1, origin_leg, destination_leg, changes, changes_list
465
469
  else:
466
- return None, None, None, None, None
470
+ return None, None, None, None, None, None
467
471
 
468
472
  # Hmm, we didn't find one
469
- return None, None, None, None, None
473
+ return None, None, None, None, None, None
470
474
 
471
475
 
472
476
  def _find_first_leg(self, legs, transport_type, strict, route_filter):
@@ -526,11 +530,13 @@ class TransportNSWv2(object):
526
530
 
527
531
  def _find_changes(self, legs, origin_leg, destination_leg):
528
532
  # Find out how often we have to change. Immediately return 0 if the origin and destination legs are the same
533
+ changes_list = []
529
534
  if origin_leg == destination_leg:
530
- return 0
535
+ return 0, changes_dict
531
536
 
532
537
  # Count the changes, each time we hit new non-walking leg is considered to be a change
533
538
  changes = 0
539
+ last_change =''
534
540
  bInJourney = False
535
541
 
536
542
  for leg in legs:
@@ -538,17 +544,36 @@ class TransportNSWv2(object):
538
544
  # We're in the journey so start capturing changes
539
545
  bInJourney = True
540
546
 
547
+ # Capture the destination, it's the first change. From now on we capture both the origin and the destination until we hit the final leg, in which we only capture the origin
548
+ last_change = leg['destination']['disassembledName']
549
+ changes_list.append(last_change)
550
+
541
551
  elif bInJourney:
542
552
  leg_class = leg['transportation']['product']['class']
543
553
  if leg_class < 99:
544
554
  if leg != destination_leg:
545
555
  changes += 1
546
556
 
557
+ # Also capture the origin and destination as a change, unless it's the same platform or stop as the last one
558
+ new_change_origin = leg['origin']['disassembledName']
559
+ new_change_destination = leg['destination']['disassembledName']
560
+
561
+ if new_change_origin != last_change:
562
+ changes_list.append(new_change_origin)
563
+ changes_list.append(new_change_destination)
564
+
565
+ last_change = new_change_destination
566
+
547
567
  if leg == destination_leg:
548
- return changes
568
+ # Capture the last change int he dictionary, again as long as it isn't the same as the previous change location
569
+ new_change_origin = leg['origin']['disassembledName']
570
+ if new_change_origin != last_change:
571
+ changes_list.append(new_change_origin)
572
+
573
+ return changes, changes_list
549
574
 
550
575
  # We should never get here!
551
- return 999
576
+ return 999, {}
552
577
 
553
578
 
554
579
  def _find_alerts(self, legs, priority_filter, alert_type):
@@ -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.3",
8
+ version="2.0.5",
9
9
  author="andystewart999",
10
10
  author_email="andy.stewart@live.com",
11
11
  description="Get detailed per-trip transport information from TransportNSW",