From cf642fc00ffda485828ce237f11a7f1f6eb7a1c2 Mon Sep 17 00:00:00 2001 From: profitroll Date: Tue, 27 Sep 2022 15:12:15 +0200 Subject: [PATCH 1/4] product const added --- pyrmv/__init__.py | 1 + pyrmv/const/__init__.py | 0 pyrmv/const/product.py | 20 ++++++++++++++++++++ setup.py | 1 + 4 files changed, 22 insertions(+) create mode 100644 pyrmv/const/__init__.py create mode 100644 pyrmv/const/product.py diff --git a/pyrmv/__init__.py b/pyrmv/__init__.py index b669181..0639791 100644 --- a/pyrmv/__init__.py +++ b/pyrmv/__init__.py @@ -29,4 +29,5 @@ from . import raw from . import errors from . import utility from . import classes +from . import const from .methods import * \ No newline at end of file diff --git a/pyrmv/const/__init__.py b/pyrmv/const/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyrmv/const/product.py b/pyrmv/const/product.py new file mode 100644 index 0000000..e635ae1 --- /dev/null +++ b/pyrmv/const/product.py @@ -0,0 +1,20 @@ +from typing import Dict + +# Constant is taken from source of PyRMVtransport: +# https://github.com/cgtobi/PyRMVtransport/blob/development/RMVtransport/const.py +PRODUCTS: Dict[str, int] = { + "ICE": 1, + "IC": 2, + "EC": 2, + "R": 4, + "RB": 4, + "RE": 4, + "S": 8, + "U-Bahn": 16, + "Tram": 32, + "Bus": 64, + "Bus2": 128, + "Fähre": 256, + "Taxi": 512, + "Bahn": 1024, +} \ No newline at end of file diff --git a/setup.py b/setup.py index b0efd36..03de73b 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ setup( packages=[ "pyrmv", "pyrmv.raw", + "pyrmv.const", "pyrmv.errors", "pyrmv.methods", "pyrmv.utility", From 5e4ca078770e557ae28a099e708875511b26a996 Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 28 Sep 2022 12:31:41 +0200 Subject: [PATCH 2/4] Started work on enums --- pyrmv/__init__.py | 3 ++- pyrmv/classes/Product.py | 4 ---- pyrmv/const/product.py | 28 +++++++++++------------ pyrmv/enums/__init__.py | 2 ++ pyrmv/enums/auto_name.py | 19 ++++++++++++++++ pyrmv/enums/product.py | 48 ++++++++++++++++++++++++++++++++++++++++ pyrmv/enums/rt_mode.py | 20 +++++++++++++++++ setup.py | 2 +- 8 files changed, 106 insertions(+), 20 deletions(-) delete mode 100644 pyrmv/classes/Product.py create mode 100644 pyrmv/enums/__init__.py create mode 100644 pyrmv/enums/auto_name.py create mode 100644 pyrmv/enums/product.py create mode 100644 pyrmv/enums/rt_mode.py diff --git a/pyrmv/__init__.py b/pyrmv/__init__.py index 0639791..a44626f 100644 --- a/pyrmv/__init__.py +++ b/pyrmv/__init__.py @@ -26,8 +26,9 @@ __license__ = "MIT License" __author__ = "Profitroll" from . import raw +from . import const +from . import enums from . import errors from . import utility from . import classes -from . import const from .methods import * \ No newline at end of file diff --git a/pyrmv/classes/Product.py b/pyrmv/classes/Product.py deleted file mode 100644 index b19b967..0000000 --- a/pyrmv/classes/Product.py +++ /dev/null @@ -1,4 +0,0 @@ -class Product(): - - def __init__(self): - pass \ No newline at end of file diff --git a/pyrmv/const/product.py b/pyrmv/const/product.py index e635ae1..fe6087e 100644 --- a/pyrmv/const/product.py +++ b/pyrmv/const/product.py @@ -3,18 +3,18 @@ from typing import Dict # Constant is taken from source of PyRMVtransport: # https://github.com/cgtobi/PyRMVtransport/blob/development/RMVtransport/const.py PRODUCTS: Dict[str, int] = { - "ICE": 1, - "IC": 2, - "EC": 2, - "R": 4, - "RB": 4, - "RE": 4, - "S": 8, - "U-Bahn": 16, - "Tram": 32, - "Bus": 64, - "Bus2": 128, - "Fähre": 256, - "Taxi": 512, - "Bahn": 1024, + "ice": 1, + "ic": 2, + "ec": 2, + "r": 4, + "rb": 4, + "re": 4, + "sbahn": 8, + "ubahn": 16, + "tram": 32, + "bus": 64, + "bus2": 128, + "ferry": 256, + "taxi": 512, + "bahn": 1024, } \ No newline at end of file diff --git a/pyrmv/enums/__init__.py b/pyrmv/enums/__init__.py new file mode 100644 index 0000000..986de86 --- /dev/null +++ b/pyrmv/enums/__init__.py @@ -0,0 +1,2 @@ +from .product import Product +from .rt_mode import RealTimeMode \ No newline at end of file diff --git a/pyrmv/enums/auto_name.py b/pyrmv/enums/auto_name.py new file mode 100644 index 0000000..fa8a5fe --- /dev/null +++ b/pyrmv/enums/auto_name.py @@ -0,0 +1,19 @@ +# Class is taken from source code of Pyrogram: +# https://github.com/pyrogram/pyrogram/blob/master/pyrogram/enums/auto_name.py + +from enum import Enum +from pyrmv.const.product import PRODUCTS + +class AutoName(Enum): + def __init__(self, code) -> None: + self.code = code + + def _generate_next_value_(self, *args): + return self.lower() + + def __repr__(self): + return f"pyrmv.enums.{self}" + +class AutoNameProduct(AutoName): + def __init__(self, code) -> None: + self.code = PRODUCTS[code] \ No newline at end of file diff --git a/pyrmv/enums/product.py b/pyrmv/enums/product.py new file mode 100644 index 0000000..2beb60c --- /dev/null +++ b/pyrmv/enums/product.py @@ -0,0 +1,48 @@ +from enum import auto +from .auto_name import AutoNameProduct + +class Product(AutoNameProduct): + """Enumeration used to declare types of transport.""" + + ICE = auto() + "The Intercity Express (commonly known as ICE) is a system of high-speed trains predominantly running in Germany." + + IC = auto() + "InterCity (commonly abbreviated IC on timetables and tickets) is the classification applied to certain long-distance passenger train services in Europe. Such trains (in contrast to regional, local, or commuter trains) generally call at major stations only." + + EC = auto() + "EuroCity, abbreviated as EC, is a cross-border train category within the European inter-city rail network. In contrast to trains allocated to the lower-level \"IC\" (InterCity) category, EC trains are international services that meet 20 criteria covering comfort, speed, food service, and cleanliness." + + R = auto() + "Regional rail, also known as local trains and stopping trains, are passenger rail services that operate between towns and cities. These trains operate with more stops over shorter distances than inter-city rail, but fewer stops and faster service than commuter rail." + + RB = auto() + "The Regionalbahn (lit. Regional train; abbreviated RB) is a type of local passenger train (stopping train) in Germany. It is similar to the Regionalzug (R) and Regio (R) train categories in neighboring Austria and Switzerland, respectively." + + RE = auto() + "In Germany, Luxembourg and Austria, the Regional-Express (RE, or in Austria: REX) is a type of regional train. It is similar to a semi-fast train, with average speed at about 70-90 km/h (top speed often 160 km/h) as it calls at fewer stations than Regionalbahn or S-Bahn trains, but stops more often than InterCity services." + + SBAHN = auto() + "The S-Bahn is the name of hybrid urban-suburban rail systems serving a metropolitan region in German-speaking countries. Some of the larger S-Bahn systems provide service similar to rapid transit systems, while smaller ones often resemble commuter or even regional rail. The term derives from Schnellbahn, Stadtbahn or Stadtschnellbahn." + + UBAHN = auto() + "A U-Bahn (short for subway, underground express train or metropolitan) is a usually underground, rail-bound means of transport for urban public transport (ÖPNV, city transport)." + + TRAM = auto() + "A tram (also known as a streetcar or trolley in North America) is a rail vehicle that travels on tramway tracks on public urban streets; some include segments on segregated right-of-way." + + BUS = auto() + "A bus (contracted from omnibus, with variants multibus, motorbus, autobus, etc.) is a road vehicle that carries significantly more passengers than an average car or van." + + BUS2 = auto() + "" + + FERRY = auto() + + + TAXI = auto() + + + BAHN = auto() + + \ No newline at end of file diff --git a/pyrmv/enums/rt_mode.py b/pyrmv/enums/rt_mode.py new file mode 100644 index 0000000..97c1b4b --- /dev/null +++ b/pyrmv/enums/rt_mode.py @@ -0,0 +1,20 @@ +from enum import auto +from .auto_name import AutoName + +class RealTimeMode(AutoName): + """Enumeration used to declare types of real-time traffic.""" + + FULL = auto() + "Combined search on planned and real-time data This search consists of two steps: i. Search on scheduled data ii. If the result of step (i) contains a non-feasible connection, a search on real-time data is performed and all results are combined" + + INFOS = auto() + "Search on planned data, use real-time information for display only: Connections are computed on the basis of planned data. Delays and feasibility of the connections are integrated into the result. Note that additional trains (supplied via realtime feed) will not be part of the resulting connections." + + OFF = auto() + "Search on planned data, ignore real-time information completely: Connections are computed on the basis of planned data. No real-time information is shown." + + REALTIME = auto() + "Search on real-time data: Connections are computed on the basis of real-time data, using planned schedule only whenever no real-time data is available. All connections computed are feasible with respect to the currently known real-time situation. Additional trains (supplied via real-time feed) will be found if these are part of a fast, comfortable, or direct connection (or economic connection, if economic search is activated)." + + SERVER_DEFAULT = auto() + "One of the other real-times modes used by default for RMV." \ No newline at end of file diff --git a/setup.py b/setup.py index 03de73b..2823f36 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ setup( "isodate" ], classifiers=[ - "Development Status :: 1 - Planning", + "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", From 37727e38bfcb35e7a65ca7effe160ea364358954 Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 28 Sep 2022 15:12:41 +0200 Subject: [PATCH 3/4] More enums added --- pyrmv/enums/__init__.py | 6 ++++- pyrmv/enums/filter_mode.py | 14 ++++++++++++ pyrmv/enums/lang.py | 41 +++++++++++++++++++++++++++++++++++ pyrmv/enums/location_type.py | 32 +++++++++++++++++++++++++++ pyrmv/enums/product.py | 9 ++++---- pyrmv/enums/selection_mode.py | 11 ++++++++++ 6 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 pyrmv/enums/filter_mode.py create mode 100644 pyrmv/enums/lang.py create mode 100644 pyrmv/enums/location_type.py create mode 100644 pyrmv/enums/selection_mode.py diff --git a/pyrmv/enums/__init__.py b/pyrmv/enums/__init__.py index 986de86..efb8cd1 100644 --- a/pyrmv/enums/__init__.py +++ b/pyrmv/enums/__init__.py @@ -1,2 +1,6 @@ from .product import Product -from .rt_mode import RealTimeMode \ No newline at end of file +from .rt_mode import RealTimeMode +from .lang import Language +from .location_type import LocationType +from .selection_mode import SelectionMode +from .filter_mode import FilterMode \ No newline at end of file diff --git a/pyrmv/enums/filter_mode.py b/pyrmv/enums/filter_mode.py new file mode 100644 index 0000000..69414fc --- /dev/null +++ b/pyrmv/enums/filter_mode.py @@ -0,0 +1,14 @@ +from enum import auto +from .auto_name import AutoName + +class FilterMode(AutoName): + """Enumeration used to declare filters for nearby searches.""" + + DIST_PERI = auto() + "Accentuate matches. Matches in the radius are first." + + EXCL_PERI = auto() + "Returns matches inside the radius only." + + SLCT_PERI = auto() + "Matches in the radius are excluded. Returns matches outside the radius only." \ No newline at end of file diff --git a/pyrmv/enums/lang.py b/pyrmv/enums/lang.py new file mode 100644 index 0000000..f87c13f --- /dev/null +++ b/pyrmv/enums/lang.py @@ -0,0 +1,41 @@ +from enum import auto +from .auto_name import AutoName + +class Language(AutoName): + """Enumeration used to declare locales as ISO-3166 codes (but only available in HAFAS ones).""" + + DE = auto() + "German" + + DA = auto() + "Danish" + + EN = auto() + "English" + + ES = auto() + "Spanish" + + FR = auto() + "French" + + HU = auto() + "Hungarian" + + IT = auto() + "Italian" + + NL = auto() + "Dutch" + + NO = auto() + "Norwegian" + + PL = auto() + "Polish" + + SV = auto() + "Swedish" + + TR = auto() + "Turkish" \ No newline at end of file diff --git a/pyrmv/enums/location_type.py b/pyrmv/enums/location_type.py new file mode 100644 index 0000000..4208b4b --- /dev/null +++ b/pyrmv/enums/location_type.py @@ -0,0 +1,32 @@ +from enum import auto +from .auto_name import AutoName + +class LocationType(AutoName): + """Enumeration used to declare types of location filter.""" + + S = auto() + "Search for station/stops only" + + A = auto() + "Search for addresses only" + + P = auto() + "Search for POIs only" + + AP = auto() + "Search for addresses and POIs" + + SA = auto() + "Search for station/stops and addresses" + + SE = auto() + "Search for stations/stops and entrypoints" + + SP = auto() + "Search for stations/stops and POIs" + + ALL = auto() + "Search in all existing location pools" + + SPE = auto() + "Search for stations/stops, POIs and entrypoints" \ No newline at end of file diff --git a/pyrmv/enums/product.py b/pyrmv/enums/product.py index 2beb60c..45bf631 100644 --- a/pyrmv/enums/product.py +++ b/pyrmv/enums/product.py @@ -35,14 +35,13 @@ class Product(AutoNameProduct): "A bus (contracted from omnibus, with variants multibus, motorbus, autobus, etc.) is a road vehicle that carries significantly more passengers than an average car or van." BUS2 = auto() - "" + "Also a bus, but now idea why it exists anyway." FERRY = auto() - + "A ferry is a ship used to carry passengers, and sometimes vehicles and cargo, across a body of water." TAXI = auto() - + "A taxi, also known as a taxicab or simply a cab, is a type of vehicle for hire with a driver, used by a single passenger or small group of passengers, often for a non-shared ride." BAHN = auto() - - \ No newline at end of file + "Rail transport (also known as train transport) is a means of transport that transfers passengers and goods on wheeled vehicles running on rails, which are located on tracks. In contrast to road transport, where the vehicles run on a prepared flat surface, rail vehicles (rolling stock) are directionally guided by the tracks on which they run." \ No newline at end of file diff --git a/pyrmv/enums/selection_mode.py b/pyrmv/enums/selection_mode.py new file mode 100644 index 0000000..0bb5f61 --- /dev/null +++ b/pyrmv/enums/selection_mode.py @@ -0,0 +1,11 @@ +from enum import auto +from .auto_name import AutoName + +class SelectionMode(AutoName): + """Enumeration used to declare location selection modes.""" + + SLCT_A = auto() + "Selectable" + + SLCT_N = auto() + "Not selectable" \ No newline at end of file From 6c9a90d455dc92b7604febbf305344639eeca313 Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 28 Sep 2022 15:12:54 +0200 Subject: [PATCH 4/4] Non-raw methods now use enums --- pyrmv/methods/stop_by_coords.py | 25 +++++---- pyrmv/methods/stop_by_name.py | 42 ++++++++------- pyrmv/methods/trip_find.py | 92 +++++++++++++++++---------------- 3 files changed, 84 insertions(+), 75 deletions(-) diff --git a/pyrmv/methods/stop_by_coords.py b/pyrmv/methods/stop_by_coords.py index 5dc6058..45731de 100644 --- a/pyrmv/methods/stop_by_coords.py +++ b/pyrmv/methods/stop_by_coords.py @@ -1,5 +1,8 @@ from typing import List, Union from pyrmv.classes.Stop import Stop +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 try: @@ -13,11 +16,11 @@ def stop_by_coords( coords_lat: Union[str, float], coords_lon: Union[str, float], - lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en", + lang: Literal[Language.DE, Language.DA, Language.EN, Language.ES, Language.FR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.SV, Language.TR] = Language.EN, radius: Union[int, float] = 1000, max_number: int = 10, - stop_type: Literal["S", "P", "SP", "SE", "SPE"] = "S", - selection_mode: Literal["SLCT_N", "SLCT_A"] = None, # type: ignore + stop_type: Literal[LocationType.S, LocationType.P, LocationType.SP, LocationType.SE, LocationType.SPE] = LocationType.S, + selection_mode: Literal[SelectionMode.SLCT_A, SelectionMode.SLCT_N] = None, # type: ignore ) -> List[Stop]: """Method returns a list of stops around a given center coordinate. The returned results are ordered by their distance to the center coordinate. @@ -28,11 +31,11 @@ def stop_by_coords( * access_id (`str`): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * coords_lat (`Union[str, float]`): Latitude of centre coordinate. * coords_lon (`Union[str, float]`): Longitude of centre coordinate. - * lang (`Literal["de","da","en","es","fr","hu","it","nl","no","pl","sv","tr"]`, **optional**): The language of response. Defaults to "en". - * radius (`Union[int, float]`, **optional**): Search radius in meter around the given coordinate if any. Defaults to 1000. - * max_number (`int`, **optional**): Maximum number of returned stops. Defaults to 10. - * stop_type (`Literal["S", "P", "SP", "SE", "SPE"]`, **optional**): Type filter for location types. Defaults to "S". - * selection_mode (`Literal["SLCT_N", "SLCT_A"]`, **optional**): Selection mode for locations. Defaults to None. + * lang (`Literal[Language.DE, Language.DA, Language.EN, Language.ES, Language.FR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.SV, Language.TR]`, **optional**): The language of response. Defaults to `Language.EN`. + * radius (`Union[int, float]`, **optional**): Search radius in meter around the given coordinate if any. Defaults to `1000`. + * max_number (`int`, **optional**): Maximum number of returned stops. Defaults to `10`. + * stop_type (`Literal[LocationType.S, LocationType.P, LocationType.SP, LocationType.SE, LocationType.SPE]`, **optional**): Type filter for location types. Defaults to `LocationType.S`. + * selection_mode (`Literal[SelectionMode.SLCT_A, SelectionMode.SLCT_N]`, **optional**): Selection mode for locations. `SelectionMode.SLCT_N`: Not selectable, `SelectionMode.SLCT_A`: Selectable. Defaults to `None`. ### Returns: * dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. @@ -43,11 +46,11 @@ def stop_by_coords( accessId=access_id, originCoordLat=coords_lat, originCoordLong=coords_lon, - lang=lang, + lang=lang.code, radius=radius, maxNo=max_number, - stopType=stop_type, - locationSelectionMode=selection_mode + stopType=(stop_type.code).upper(), + locationSelectionMode=(selection_mode.code).upper() ) for stop in stops_raw["stopLocationOrCoordLocation"]: diff --git a/pyrmv/methods/stop_by_name.py b/pyrmv/methods/stop_by_name.py index 090fb32..01c3771 100644 --- a/pyrmv/methods/stop_by_name.py +++ b/pyrmv/methods/stop_by_name.py @@ -1,5 +1,9 @@ from typing import List, Union from pyrmv.classes.Stop import Stop +from pyrmv.enums.location_type import LocationType +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 try: @@ -12,16 +16,16 @@ def stop_by_name( access_id: str, query: str, - lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en", + lang: Literal[Language.DE, Language.DA, Language.EN, Language.ES, Language.FR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.SV, Language.TR] = Language.EN, max_number: int = 10, - stop_type: Literal["A", "ALL", "AP", "P", "S", "SA", "SP"] = "ALL", - selection_mode: Literal["SLCT_N", "SLCT_A"] = None, # type: ignore + stop_type: Literal[LocationType.A, LocationType.ALL, LocationType.AP, LocationType.P, LocationType.S, LocationType.SA, LocationType.SP] = LocationType.ALL, + selection_mode: Literal[SelectionMode.SLCT_A, SelectionMode.SLCT_N] = None, # type: ignore coord_lat: Union[str, float] = None, # type: ignore coord_lon: Union[str, float] = None, # type: ignore radius: Union[int, float] = 1000, refine_id: str = None, # type: ignore stations: Union[str, list] = None, # type: ignore - filter_mode: Literal["DIST_PERI", "EXCL_PERI", "SLCT_PERI"] = "DIST_PERI" + filter_mode: Literal[FilterMode.DIST_PERI, FilterMode.EXCL_PERI, FilterMode.SLCT_PERI] = FilterMode.DIST_PERI ) -> List[Stop]: """Method can be used to perform a pattern matching of a user input and to retrieve a list of possible matches in the journey planner database. Possible matches might be stops/stations, @@ -30,18 +34,18 @@ def stop_by_name( More detailed request is available as raw.stop_by_name(), however returns dict instead of List[Stop]. ### Args: - * access_id (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). - * query (str): Search for that token. - * lang (Literal["de","da","en","es","fr","hu","it","nl","no","pl","sv","tr"], optional): The language of response. Defaults to "en". - * max_number (int, optional): Maximum number of returned stops. In range 1-1000. Defaults to 10. - * stop_type (Literal["A", "ALL", "AP", "P", "S", "SA", "SP"], optional): Type filter for location types. Defaults to "ALL". - * selection_mode (str, optional): Selection mode for locations. "SLCT_N": Not selectable, "SLCT_A": Selectable. Defaults to None. - * coord_lat (Union[str, float], optional): Latitude of centre coordinate. Defaults to None. - * coord_lon (Union[str, float], optional): Longitude of centre coordinate. Defaults to None. - * radius (Union[int, float], optional): Search radius in meter around the given coordinate if any. Defaults to 1000. - * refine_id (str, optional): In case of an refinable location, this value takes the ID of the refinable one of a previous result. Defaults to None. - * stations (Union[str, list], optional): Filter for stations. Matches if the given value is prefix of any station in the itinerary. As a list or as a string separated by comma. Defaults to None. - * filter_mode (Literal["DIST_PERI", "EXCL_PERI", "SLCT_PERI"], optional): Filter modes for nearby searches. Defaults to "DIST_PERI". + * access_id (`str`): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). + * query (`str`): Search for that token. + * lang (`Literal[Language.DE, Language.DA, Language.EN, Language.ES, Language.FR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.SV, Language.TR]`, **optional**): The language of response. Defaults to `Language.EN`. + * max_number (`int`, **optional**): Maximum number of returned stops. In range 1-1000. Defaults to `10`. + * stop_type (`Literal[LocationType.A, LocationType.ALL, LocationType.AP, LocationType.P, LocationType.S, LocationType.SA, LocationType.SP]`, **optional**): Type filter for location types. Defaults to `LocationType.ALL`. + * selection_mode (`Literal[SelectionMode.SLCT_A, SelectionMode.SLCT_N]`, **optional**): Selection mode for locations. `SelectionMode.SLCT_N`: Not selectable, `SelectionMode.SLCT_A`: Selectable. Defaults to `None`. + * coord_lat (`Union[str, float]`, **optional**): Latitude of centre coordinate. Defaults to `None`. + * coord_lon (`Union[str, float]`, **optional**): Longitude of centre coordinate. Defaults to `None`. + * radius (`Union[int, float]`, **optional**): Search radius in meter around the given coordinate if any. Defaults to `1000`. + * refine_id (`str`, **optional**): In case of an refinable location, this value takes the ID of the refinable one of a previous result. Defaults to `None`. + * stations (`Union[str, list]`, **optional**): Filter for stations. Matches if the given value is prefix of any station in the itinerary. As a list or as a string separated by comma. Defaults to `None`. + * filter_mode (`Literal[FilterMode.DIST_PERI, FilterMode.EXCL_PERI, FilterMode.SLCT_PERI]`, **optional**): Filter modes for nearby searches. Defaults to `FilterMode.DIST_PERI`. ### Returns: * dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. @@ -51,10 +55,10 @@ def stop_by_name( stops_raw = raw_stop_by_name( accessId=access_id, inputString=query, - lang=lang, + lang=lang.code, maxNo=max_number, - stopType=stop_type, - locationSelectionMode=selection_mode, + stopType=(stop_type.code).upper(), + locationSelectionMode=(selection_mode.code).upper(), coordLat=coord_lat, coordLong=coord_lon, radius=radius, diff --git a/pyrmv/methods/trip_find.py b/pyrmv/methods/trip_find.py index 8f63dc6..9ea758b 100644 --- a/pyrmv/methods/trip_find.py +++ b/pyrmv/methods/trip_find.py @@ -2,6 +2,8 @@ from datetime import datetime from typing import List, Union 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 try: from typing import Literal @@ -11,7 +13,7 @@ except ImportError: def trip_find( access_id: str, - lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en", + lang: Literal[Language.DE, Language.DA, Language.EN, Language.ES, Language.FR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.SV, Language.TR] = Language.EN, origin_id: str = None, # type: ignore origin_id_ext: str = None, # type: ignore @@ -62,7 +64,7 @@ def trip_find( passing_points: bool = False, - real_time_mode: Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"] = None, # type: ignore + real_time_mode: Literal[RealTimeMode.FULL, RealTimeMode.INFOS, RealTimeMode.OFF, RealTimeMode.REALTIME, RealTimeMode.SERVER_DEFAULT] = None, # type: ignore include_earlier: bool = False, ict_alternatives: bool = False, @@ -78,48 +80,48 @@ def trip_find( ### Args: * access_id (`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". - * origin_id (`str`, **optional**): Specifies the station/stop ID of the origin for the trip. Such ID can be retrieved from stop_by_name() or stop_by_coords(). Defaults to None. - * origin_id_ext (`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 stop_by_name() or stop_by_coords(). Defaults to None. - * origin_coord_lat (`Union[str, float]`, **optional**): Latitude of station/stop coordinate of the trip's origin. The coordinate can be retrieved from stop_by_name() or stop_by_coords(). Defaults to None. - * origin_coord_lon (`Union[str, float]`, **optional**): Longitude of station/stop coordinate of the trip's origin. The coordinate can be retrieved from stop_by_name() or stop_by_coords(). Defaults to None. - * origin_coord_name (`str`, **optional**): Name of the trip's origin if coordinate cannot be resolved to an address or poi. Defaults to None. - * destination_id (`str`, **optional**): Specifies the station/stop ID of the destination for the trip. Such ID can be retrieved from stop_by_name() or stop_by_coords(). Defaults to None. - * destination_id_ext (`str`, **optional**): Deprecated. Please use destId as it supports external IDs. Specifies the external station/stop ID of the destination for the trip. Such ID can be retrieved from stop_by_name() or stop_by_coords(). Defaults to None. - * destination_coord_lat (`Union[str, float]`, **optional**): Latitude of station/stop coordinate of the trip's destination. The coordinate can be retrieved from stop_by_name() or stop_by_coords(). Defaults to None. - * destination_coord_lon (`Union[str, float]`, **optional**): Longitude of station/stop coordinate of the trip's destination. The coordinate can be retrieved from stop_by_name() or stop_by_coords(). Defaults to None. - * destination_coord_name (`str`, **optional**): Name of the trip's destination if coordinate cannot be resolved to an address or poi. Defaults to None. - * via (`str`, **optional**): Complex structure to provide multiple via points separated by semicolon. This structure is build like this: `viaId|waittime|viastatus|products|direct|sleepingCar|couchetteCoach|attributes`. Read more about this in HAFAS ReST Documentation. Defaults to None. - * via_id (`str`, **optional**): ID of a station/stop used as a via for the trip. Specifying a via station forces the trip search to look for trips which must pass through this station. Such ID can be retrieved from stop_by_name() or stop_by_coords(). If `via` is used, `via_id` and `via_wait_time ` are having no effect. Defaults to None. - * via_gis (`str`, **optional**): Complex structure to provide multiple GIS via locations separated by semicolon. This structure is build like this: `locationId|locationMode|transportMode|placeType|usageType|mode|durationOfStay`. Read more about this in HAFAS ReST Documentation. Defaults to None. + * lang (`Literal[Language.DE, Language.DA, Language.EN, Language.ES, Language.FR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.SV, Language.TR]`, **optional**): The language of response. Defaults to `Language.EN`. + * origin_id (`str`, **optional**): Specifies the station/stop ID of the origin for the trip. Such ID can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`. + * origin_id_ext (`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 stop_by_name() or stop_by_coords(). Defaults to `None`. + * origin_coord_lat (`Union[str, float]`, **optional**): Latitude of station/stop coordinate of the trip's origin. The coordinate can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`. + * origin_coord_lon (`Union[str, float]`, **optional**): Longitude of station/stop coordinate of the trip's origin. The coordinate can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`. + * origin_coord_name (`str`, **optional**): Name of the trip's origin if coordinate cannot be resolved to an address or poi. Defaults to `None`. + * destination_id (`str`, **optional**): Specifies the station/stop ID of the destination for the trip. Such ID can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`. + * destination_id_ext (`str`, **optional**): Deprecated. Please use destId as it supports external IDs. Specifies the external station/stop ID of the destination for the trip. Such ID can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`. + * destination_coord_lat (`Union[str, float]`, **optional**): Latitude of station/stop coordinate of the trip's destination. The coordinate can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`. + * destination_coord_lon (`Union[str, float]`, **optional**): Longitude of station/stop coordinate of the trip's destination. The coordinate can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`. + * destination_coord_name (`str`, **optional**): Name of the trip's destination if coordinate cannot be resolved to an address or poi. Defaults to `None`. + * via (`str`, **optional**): Complex structure to provide multiple via points separated by semicolon. This structure is build like this: `viaId|waittime|viastatus|products|direct|sleepingCar|couchetteCoach|attributes`. Read more about this in HAFAS ReST Documentation. Defaults to `None`. + * via_id (`str`, **optional**): ID of a station/stop used as a via for the trip. Specifying a via station forces the trip search to look for trips which must pass through this station. Such ID can be retrieved from stop_by_name() or stop_by_coords(). If `via` is used, `via_id` and `via_wait_time ` are having no effect. Defaults to `None`. + * via_gis (`str`, **optional**): Complex structure to provide multiple GIS via locations separated by semicolon. This structure is build like this: `locationId|locationMode|transportMode|placeType|usageType|mode|durationOfStay`. Read more about this in HAFAS ReST Documentation. Defaults to `None`. * via_wait_time (`int`, **optional**): Defines the waiting time spent at via station in minutes. If `via` is used, `via_id` and `via_wait_time` are having no effect. Defaults to 0. - * avoid (`str`, **optional**): Complex structure to provide multiple points to be avoided separated by semicolon. This structure is build like this: `avoidId|avoidstatus` avoidId: id, extId or altId of the avoid, mandatory avoidstatus: one of NPAVM (do not run through if this is a meta station), NPAVO (do not run through), NCAVM (do not change if this is a meta station), NCAVO (do not change), optional but defaults to NCAVM Example: Just define three avoids by extId: `avoid="801234;801235;801236"`. Defaults to None. - * avoid_id (`str`, **optional**): ID of a station/stop to be avoided as transfer stop for the trip. Such ID can be retrieved from stop_by_name() or stop_by_coords(). If `avoid` is used, `avoid_id` has no effect. Defaults to None. - * change_time_percent (`int`, **optional**): Configures the walking speed when changing from one leg of the journey to the next one. It extends the time required for changes by a specified percentage. A value of 200 doubles the change time as initially calculated by the system. In the response, change time is presented in full minutes. If the calculation based on changeTime-Percent does not result in a full minute, it is rounded using "round half up" method. Defaults to 100. - * change_time_min (`int`, **optional**): Minimum change time at stop in minutes. Defaults to None. - * change_time_max (`int`, **optional**): Maximum change time at stop in minutes. Defaults to None. - * change_time_add (`int`, **optional**): This amount of minutes is added to the change time at each stop. Defaults to None. - * change_max (`int`, **optional**): Maximum number of changes. In range 0-11. Defaults to None. - * date (`str`, **optional**): Sets the start date for which the departures shall be retrieved. Represented in the format `YYYY-MM-DD`. By default the current server date is used. Defaults to None. - * time (`str`, **optional**): Sets the start time for which the departures shall be retrieved. Represented in the format `hh:mm[:ss]` in 24h nomenclature. Seconds will be ignored for requests. By default the current server time is used. Defaults to None. - * search_arrival (`bool`, **optional**): If set, the date and time parameters specify the arrival time for the trip search instead of the departure time. Defaults to False. - * trips_after_time (`int`, **optional**): Minimum number of trips after the search time. Sum of `trips_after_time` and `trips_before_time` has to be less or equal 6. Read more about this in HAFAS ReST Documentation. In range 1-6. Defaults to None. - * trips_before_time (`int`, **optional**): Minimum number of trips before the search time. Sum of `trips_after_time` and `trips_before_time` has to be less or equal 6. Read more about this in HAFAS ReST Documentation. In range 0-6. Defaults to None. - * context (`str`, **optional**): Defines the starting point for the scroll back or forth operation. Use the scrB value from a previous result to scroll backwards in time and use the scrF value to scroll forth. Defaults to None. - * passlist (`bool`, **optional**): Enables/disables the return of the passlist for each leg of the trip. Defaults to False. - * operators (`Union[str, list]`, **optional**): Only trips provided by the given operators are part of the result. If the operator should not be part of the be trip, negate it by putting ! in front of it. Example: Filter for operator A and B: `operators=["A","B"]`. Defaults to None. - * lines (`Union[str, list]`, **optional**): Only journeys running the given line are part of the result. If the line should not be part of the be trip, negate it by putting ! in front of it. Defaults to None. - * lineids (`Union[str, list]`, **optional**): Only journeys running the given line (identified by its line ID) are part of the result. If the line should not be part of the be trip, negate it by putting ! in front of it. Defaults to None. - * iv_include (`bool`, **optional**): Enables/disables search for individual transport routes. Defaults to False. - * iv_only (`bool`, **optional**): Enables/disables search for individual transport routes only. Defaults to False. - * bike_carriage (`bool`, **optional**): Enables/disables search for trips explicit allowing bike carriage. This will only work in combination with `change_max=0` as those trips are always meant to be direct connections. Defaults to False. - * passing_points (`bool`, **optional**): Enables/disables the return of stops having no alighting and boarding in its passlist for each leg of the trip. Needs passlist enabled. Defaults to False. - * real_time_mode (`Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"]`, **optional**): Set the realtime mode to be used. Read more about this in HAFAS ReST Documentation. Defaults to None. - * include_earlier (`bool`, **optional**): Disables search optimization in relation of duration. Defaults to False. - * ict_alternatives (`bool`, **optional**): Enables/disables the search for alternatives with individualized change times (ICT). Defaults to False. - * tariff (`bool`, **optional**): Enables/disables the output of tariff data. The default is configurable via provisioning. Defaults to None. - * messages (`bool`, **optional**): Enables/disables the output of traffic messages. The default is configurable via provisioning. Defaults to False. - * frequency (`bool`, **optional**): Enables/disables the calculation of frequency information. Defaults to True. + * avoid (`str`, **optional**): Complex structure to provide multiple points to be avoided separated by semicolon. This structure is build like this: `avoidId|avoidstatus` avoidId: id, extId or altId of the avoid, mandatory avoidstatus: one of NPAVM (do not run through if this is a meta station), NPAVO (do not run through), NCAVM (do not change if this is a meta station), NCAVO (do not change), optional but defaults to NCAVM Example: Just define three avoids by extId: `avoid="801234;801235;801236"`. Defaults to `None`. + * avoid_id (`str`, **optional**): ID of a station/stop to be avoided as transfer stop for the trip. Such ID can be retrieved from stop_by_name() or stop_by_coords(). If `avoid` is used, `avoid_id` has no effect. Defaults to `None`. + * change_time_percent (`int`, **optional**): Configures the walking speed when changing from one leg of the journey to the next one. It extends the time required for changes by a specified percentage. A value of 200 doubles the change time as initially calculated by the system. In the response, change time is presented in full minutes. If the calculation based on changeTime-Percent does not result in a full minute, it is rounded using "round half up" method. Defaults to `100`. + * change_time_min (`int`, **optional**): Minimum change time at stop in minutes. Defaults to `None`. + * change_time_max (`int`, **optional**): Maximum change time at stop in minutes. Defaults to `None`. + * change_time_add (`int`, **optional**): This amount of minutes is added to the change time at each stop. Defaults to `None`. + * change_max (`int`, **optional**): Maximum number of changes. In range 0-11. Defaults to `None`. + * date (`str`, **optional**): Sets the start date for which the departures shall be retrieved. Represented in the format `YYYY-MM-DD`. By default the current server date is used. Defaults to `None`. + * time (`str`, **optional**): Sets the start time for which the departures shall be retrieved. Represented in the format `hh:mm[:ss]` in 24h nomenclature. Seconds will be ignored for requests. By default the current server time is used. Defaults to `None`. + * search_arrival (`bool`, **optional**): If set, the date and time parameters specify the arrival time for the trip search instead of the departure time. Defaults to `False`. + * trips_after_time (`int`, **optional**): Minimum number of trips after the search time. Sum of `trips_after_time` and `trips_before_time` has to be less or equal 6. Read more about this in HAFAS ReST Documentation. In range 1-6. Defaults to `None`. + * trips_before_time (`int`, **optional**): Minimum number of trips before the search time. Sum of `trips_after_time` and `trips_before_time` has to be less or equal 6. Read more about this in HAFAS ReST Documentation. In range 0-6. Defaults to `None`. + * context (`str`, **optional**): Defines the starting point for the scroll back or forth operation. Use the scrB value from a previous result to scroll backwards in time and use the scrF value to scroll forth. Defaults to `None`. + * passlist (`bool`, **optional**): Enables/disables the return of the passlist for each leg of the trip. Defaults to `False`. + * operators (`Union[str, list]`, **optional**): Only trips provided by the given operators are part of the result. If the operator should not be part of the be trip, negate it by putting ! in front of it. Example: Filter for operator A and B: `operators=["A","B"]`. Defaults to `None`. + * lines (`Union[str, list]`, **optional**): Only journeys running the given line are part of the result. If the line should not be part of the be trip, negate it by putting ! in front of it. Defaults to `None`. + * lineids (`Union[str, list]`, **optional**): Only journeys running the given line (identified by its line ID) are part of the result. If the line should not be part of the be trip, negate it by putting ! in front of it. Defaults to `None`. + * iv_include (`bool`, **optional**): Enables/disables search for individual transport routes. Defaults to `False`. + * iv_only (`bool`, **optional**): Enables/disables search for individual transport routes only. Defaults to `False`. + * bike_carriage (`bool`, **optional**): Enables/disables search for trips explicit allowing bike carriage. This will only work in combination with `change_max=0` as those trips are always meant to be direct connections. Defaults to `False`. + * passing_points (`bool`, **optional**): Enables/disables the return of stops having no alighting and boarding in its passlist for each leg of the trip. Needs passlist enabled. Defaults to `False`. + * real_time_mode (`Literal[RealTimeMode.FULL, RealTimeMode.INFOS, RealTimeMode.OFF, RealTimeMode.REALTIME, RealTimeMode.SERVER_DEFAULT]`, **optional**): Set the realtime mode to be used. Read more about this in HAFAS ReST Documentation. Defaults to `None`. + * include_earlier (`bool`, **optional**): Disables search optimization in relation of duration. Defaults to `False`. + * ict_alternatives (`bool`, **optional**): Enables/disables the search for alternatives with individualized change times (ICT). Defaults to `False`. + * tariff (`bool`, **optional**): Enables/disables the output of tariff data. The default is configurable via provisioning. Defaults to `None`. + * messages (`bool`, **optional**): Enables/disables the output of traffic messages. The default is configurable via provisioning. Defaults to `False`. + * frequency (`bool`, **optional**): Enables/disables the calculation of frequency information. Defaults to `True`. ### Returns: * List[Trip]: List of Trip objects. Empty list if none found. @@ -129,7 +131,7 @@ def trip_find( trips_raw = raw_trip_find( accessId=access_id, - lang=lang, + lang=lang.code, originId=origin_id, originExtId=origin_id_ext, @@ -180,7 +182,7 @@ def trip_find( showPassingPoints=passing_points, - rtMode=real_time_mode, + rtMode=(real_time_mode.code).upper(), includeEarlier=include_earlier, withICTAlternatives=ict_alternatives,