From 1c68772ed45cc80bedd0a4b14f00be22a3ef0008 Mon Sep 17 00:00:00 2001 From: Profitroll <47523801+profitrollgame@users.noreply.github.com> Date: Fri, 30 Sep 2022 11:39:04 +0200 Subject: [PATCH] find_exception is only used in normal methods now --- pyrmv/methods/stop_by_coords.py | 3 +++ pyrmv/methods/stop_by_name.py | 5 ++++- pyrmv/methods/trip_find.py | 3 +++ pyrmv/raw/him_search.py | 5 +++-- pyrmv/raw/journey_detail.py | 6 +++--- pyrmv/raw/stop_by_coords.py | 7 +++---- pyrmv/raw/stop_by_name.py | 7 +++---- pyrmv/raw/trip_find.py | 8 +++++--- pyrmv/raw/trip_recon.py | 4 +++- 9 files changed, 30 insertions(+), 18 deletions(-) diff --git a/pyrmv/methods/stop_by_coords.py b/pyrmv/methods/stop_by_coords.py index 45731de..daba859 100644 --- a/pyrmv/methods/stop_by_coords.py +++ b/pyrmv/methods/stop_by_coords.py @@ -4,6 +4,7 @@ from pyrmv.enums.location_type import LocationType from pyrmv.enums.lang import Language from pyrmv.enums.selection_mode import SelectionMode from pyrmv.raw.stop_by_coords import stop_by_coords as raw_stop_by_coords +from pyrmv.utility.find_exception import find_exception try: from typing import Literal @@ -53,6 +54,8 @@ def stop_by_coords( locationSelectionMode=(selection_mode.code).upper() ) + find_exception(stops_raw) + for stop in stops_raw["stopLocationOrCoordLocation"]: if "StopLocation" in stop: stops.append(Stop(stop["StopLocation"])) diff --git a/pyrmv/methods/stop_by_name.py b/pyrmv/methods/stop_by_name.py index 01c3771..6faea8d 100644 --- a/pyrmv/methods/stop_by_name.py +++ b/pyrmv/methods/stop_by_name.py @@ -5,6 +5,7 @@ from pyrmv.enums.lang import Language from pyrmv.enums.selection_mode import SelectionMode from pyrmv.enums.filter_mode import FilterMode from pyrmv.raw.stop_by_name import stop_by_name as raw_stop_by_name +from pyrmv.utility.find_exception import find_exception try: from typing import Literal @@ -64,9 +65,11 @@ def stop_by_name( radius=radius, refineId=refine_id, stations=stations, - filterMode=filter_mode + filterMode=filter_mode.code ) + find_exception(stops_raw) + for stop in stops_raw["stopLocationOrCoordLocation"]: if "StopLocation" in stop: stops.append(Stop(stop["StopLocation"])) diff --git a/pyrmv/methods/trip_find.py b/pyrmv/methods/trip_find.py index 9ea758b..0dabc6b 100644 --- a/pyrmv/methods/trip_find.py +++ b/pyrmv/methods/trip_find.py @@ -4,6 +4,7 @@ from pyrmv.classes.Trip import Trip from pyrmv.raw.trip_find import trip_find as raw_trip_find from pyrmv.enums.rt_mode import RealTimeMode from pyrmv.enums.lang import Language +from pyrmv.utility.find_exception import find_exception try: from typing import Literal @@ -191,6 +192,8 @@ def trip_find( withFreq=frequency ) + find_exception(trips_raw) + for trip in trips_raw["Trip"]: trips.append(Trip(trip)) diff --git a/pyrmv/raw/him_search.py b/pyrmv/raw/him_search.py index 7fccf82..585a4aa 100644 --- a/pyrmv/raw/him_search.py +++ b/pyrmv/raw/him_search.py @@ -3,7 +3,6 @@ from typing import Dict, OrderedDict, Union from xmltodict import parse as xmlparse from datetime import datetime -from pyrmv.utility.find_exception import find_exception from pyrmv.utility.weekdays_bitmask import weekdays_bitmask try: @@ -124,7 +123,9 @@ def him_search(accessId: str, output = get("https://www.rmv.de/hapi/himsearch", params=payload, headers=headers) - find_exception(output.json()) + # Exceptions checker moved to normal methods + # and exceptions will no longer raise in raw ones. + # find_exception(output.json()) if json: return output.json() diff --git a/pyrmv/raw/journey_detail.py b/pyrmv/raw/journey_detail.py index 5e8110e..1a8833d 100644 --- a/pyrmv/raw/journey_detail.py +++ b/pyrmv/raw/journey_detail.py @@ -2,8 +2,6 @@ from requests import get from typing import List, Union from xmltodict import parse as xmlparse -from pyrmv.utility.find_exception import find_exception - try: from typing import Literal except ImportError: @@ -28,7 +26,9 @@ def journey_detail(accessId: str, output = get("https://www.rmv.de/hapi/journeyDetail", params=payload, headers=headers) - find_exception(output.json()) + # Exceptions checker moved to normal methods + # and exceptions will no longer raise in raw ones. + # find_exception(output.json()) if json: return output.json() diff --git a/pyrmv/raw/stop_by_coords.py b/pyrmv/raw/stop_by_coords.py index a69c271..f217367 100644 --- a/pyrmv/raw/stop_by_coords.py +++ b/pyrmv/raw/stop_by_coords.py @@ -1,9 +1,6 @@ from requests import get from typing import List, Union from xmltodict import parse as xmlparse -from pyrmv.classes.Stop import Stop - -from pyrmv.utility.find_exception import find_exception try: from typing import Literal @@ -63,7 +60,9 @@ def stop_by_coords(accessId: str, output = get("https://www.rmv.de/hapi/location.nearbystops", params=payload, headers=headers) - find_exception(output.json()) + # Exceptions checker moved to normal methods + # and exceptions will no longer raise in raw ones. + # find_exception(output.json()) if json: return output.json() diff --git a/pyrmv/raw/stop_by_name.py b/pyrmv/raw/stop_by_name.py index de92cfa..04eb97f 100644 --- a/pyrmv/raw/stop_by_name.py +++ b/pyrmv/raw/stop_by_name.py @@ -1,9 +1,6 @@ from requests import get from typing import List, Union from xmltodict import parse as xmlparse -from pyrmv.classes.Stop import Stop - -from pyrmv.utility.find_exception import find_exception try: from typing import Literal @@ -77,7 +74,9 @@ def stop_by_name(accessId: str, output = get("https://www.rmv.de/hapi/location.name", params=payload, headers=headers) - find_exception(output.json()) + # Exceptions checker moved to normal methods + # and exceptions will no longer raise in raw ones. + # find_exception(output.json()) if json: return output.json() diff --git a/pyrmv/raw/trip_find.py b/pyrmv/raw/trip_find.py index b3c970e..bd79d81 100644 --- a/pyrmv/raw/trip_find.py +++ b/pyrmv/raw/trip_find.py @@ -134,7 +134,7 @@ def trip_find(accessId: str, ### Args: * accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * lang (Literal["de","da","en","es","fr","hu","it","nl","no","pl","sv","tr"], optional): The language of response. Defaults to "en". - * json (bool, optional): Whether response should be retrieved as JSON. XML is returned if False. Only matters if raw_response is True. Defaults to True. + * json (bool, optional): Whether response should be retrieved as JSON. XML is returned if False. Defaults to True. * originId (str, optional): Specifies the station/stop ID of the origin for the trip. Such ID can be retrieved from stopByName() or stopByCoords(). Defaults to None. * originExtId (str, optional): Deprecated. Please use originId as it supports external IDs. Specifies the external station/stop ID of the origin for the trip. Such ID can be retrieved from stopByName() or stopByCoords(). Defaults to None. * originCoordLat (Union[str, float], optional): Latitude of station/stop coordinate of the trip's origin. The coordinate can be retrieved from stopByName() or stopByCoords(). Defaults to None. @@ -242,13 +242,15 @@ def trip_find(accessId: str, payload[str(var)] = val.strftime("%H:%M") else: payload[str(var)] = val - elif str(var) not in ["json", "headers", "payload", "raw_response"]: + elif str(var) not in ["json", "headers", "payload"]: if val != None: payload[str(var)] = val output = get("https://www.rmv.de/hapi/trip", params=payload, headers=headers) - find_exception(output.json()) + # Exceptions checker moved to normal methods + # and exceptions will no longer raise in raw ones. + # find_exception(output.json()) if json: return output.json() diff --git a/pyrmv/raw/trip_recon.py b/pyrmv/raw/trip_recon.py index 02cf4b3..ef88ee2 100644 --- a/pyrmv/raw/trip_recon.py +++ b/pyrmv/raw/trip_recon.py @@ -28,7 +28,9 @@ def trip_recon(accessId: str, output = get("https://www.rmv.de/hapi/recon", params=payload, headers=headers) - find_exception(output.json()) + # Exceptions checker moved to normal methods + # and exceptions will no longer raise in raw ones. + # find_exception(output.json()) if json: return output.json()