Skip to content
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

Update rmvtransport.py (Sourcery refactored) #76

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions RMVtransport/rmvtransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ async def get_departures(
direction_id: Optional[str] = None,
max_journeys: int = 20,
products: Optional[List[str]] = None,
time: Optional[str] = "now"
) -> RMVtravel:
"""Fetch data from rmv.de."""
url = self.build_journey_query(station_id, direction_id, max_journeys, products)
url = self.build_journey_query(station_id, direction_id, max_journeys, products, time)
xml = await self._query_rmv_api(url)
self.obj = extract_data_from_xml(xml)

Expand Down Expand Up @@ -85,16 +86,18 @@ def build_journey_query(
direction_id: Optional[str] = None,
max_journeys: int = 20,
products: Optional[List[str]] = None,
time: Optional[str] = "now"
) -> str:
"""Build query to request journey data."""
self.station_id = station_id
self.direction_id = direction_id
self.max_journeys = max_journeys
self.products_filter = product_filter(products or ALL_PRODUCTS)
self.time = time

params: Dict[str, Union[str, int]] = {
"selectDate": "today",
"time": "now",
"time": self.time,
"input": self.station_id,
"maxJourneys": self.max_journeys,
"boardType": "dep",
Expand Down Expand Up @@ -213,8 +216,8 @@ def base_url(path: str = STBOARD_PATH) -> str:
def convert_coordinates(value: str) -> float:
"""Convert coordinates to lat/long."""
if len(value) < 8:
return float(value[0] + "." + value[1:])
return float(value[0:2] + "." + value[2:])
return float(f"{value[0]}.{value[1:]}")
return float(f"{value[:2]}.{value[2:]}")


def extract_data_from_xml(xml: bytes) -> Any:
Expand Down
Loading