Skip to content

Implement parsing operators #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading