Skip to content

Commit

Permalink
Implement parsing operators
Browse files Browse the repository at this point in the history
  • Loading branch information
jbruechert committed Sep 24, 2024
1 parent 8dcfb69 commit c020f8a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pyhafas/profile/base/helper/parse_leg.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def parse_leg(
arrival.get('aPlatfS', arrival.get('aPltfR', arrival.get('aPltfS', {})).get('txt'))),
stopovers=leg_stopovers,
remarks=[self.parse_remark(common['remL'][msg['remX']], common)
for msg in journey.get('msgL', {}) if msg.get('remX') is not None])
for msg in journey.get('msgL', {}) if msg.get('remX') is not None],
operators=[op['name'] for op in common['opL']] if common['opL'] else None)

def parse_legs(
self: ProfileInterface,
Expand Down
6 changes: 5 additions & 1 deletion pyhafas/types/fptf.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class Leg(FPTFObject):
:vartype stopovers: Optional[List[Stopover]]
:ivar remarks: (optional) List of remarks
:vartype remarks: List[Remark]
:ivar operators: (optional) The operators of the train
:vartype operators: List[str]
"""

def __init__(
Expand All @@ -231,7 +233,8 @@ def __init__(
arrival_delay: Optional[datetime.timedelta] = None,
arrival_platform: Optional[str] = None,
stopovers: Optional[List[Stopover]] = None,
remarks: Optional[List[Remark]] = None
remarks: Optional[List[Remark]] = None,
operators: Optional[List[str]] = None
):
"""
FPTF `Leg` object
Expand Down Expand Up @@ -272,6 +275,7 @@ def __init__(
if remarks is None:
remarks = []
self.remarks: List[Remark] = remarks
self.operators = operators


class Journey(FPTFObject):
Expand Down
3 changes: 2 additions & 1 deletion tests/db/parsing/journey_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_db_journey_parsing():
priority=560,
trip_id=None
)
])]
],
operators=['DB Regio AG NRW'])]
)
assert DBProfile().parse_journey_request(hafas_response) == correct_journey
3 changes: 2 additions & 1 deletion tests/db/parsing/journeys_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def test_db_journeys_parsing():
priority=560,
trip_id=None
)
]
],
operators=['DB Regio AG NRW']
)],
)]
assert DBProfile().parse_journeys_request(hafas_response) == correct_journeys
3 changes: 2 additions & 1 deletion tests/db/parsing/trip_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ def test_db_trips_parsing():
priority=560,
trip_id=None
)
]
],
operators=['DB Regio AG NRW']
)
assert DBProfile().parse_trip_request(hafas_response) == correct_trip
3 changes: 2 additions & 1 deletion tests/vsn/parsing/journeys_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def test_vsn_journeys_parsing():
priority=899,
trip_id=None
)
]
],
operators=['NordWestBahn', 'NordWestBahn']
)
]
)
Expand Down

0 comments on commit c020f8a

Please sign in to comment.