diff --git a/README.md b/README.md index 0fac2a6..3648cb2 100644 --- a/README.md +++ b/README.md @@ -47,11 +47,11 @@ RMV API key. Just use my functions together with those docs, if you want to buil really sophisticated. However I'm not sure whether RMV supports that many HAFAS features publicly. # To-Do -- [ ] arrivalBoard (boardArrival) -- [ ] departureBoard (boardArrival) -- [x] himsearch (himSearch) -- [ ] journeyDetail -- [x] location.nearbystops (stopByCoords) -- [x] location.name (stopByName) -- [ ] recon -- [x] trip (findRoute) \ No newline at end of file +- [ ] arrivalBoard (board_arrival) +- [ ] departureBoard (board_departure) +- [x] himsearch (him_search) +- [ ] journeyDetail (journey_detail) +- [x] location.nearbystops (stop_by_coords) +- [x] location.name (stop_by_name) +- [x] trip (trip_find) +- [ ] recon (trip_recon) \ No newline at end of file diff --git a/pyrmv/raw/__init__.py b/pyrmv/raw/__init__.py index 27a64da..62fb3fd 100644 --- a/pyrmv/raw/__init__.py +++ b/pyrmv/raw/__init__.py @@ -1,7 +1,8 @@ -from .boardArrival import boardArrival -from .boardDeparture import boardDeparture -from .findRoute import findRoute -from .himSearch import himSearch -from .journeyDetail import journeyDetail -from .stopByCoords import stopByCoords -from .stopByName import stopByName \ No newline at end of file +from .board_arrival import board_arrival +from .board_departure import board_departure +from .him_search import him_search +from .journey_detail import journey_detail +from .stop_by_coords import stop_by_coords +from .stop_by_name import stop_by_name +from .trip_find import trip_find +from .trip_recon import trip_recon \ No newline at end of file diff --git a/pyrmv/raw/boardArrival.py b/pyrmv/raw/board_arrival.py similarity index 90% rename from pyrmv/raw/boardArrival.py rename to pyrmv/raw/board_arrival.py index d46bfd5..adbd43c 100644 --- a/pyrmv/raw/boardArrival.py +++ b/pyrmv/raw/board_arrival.py @@ -8,7 +8,7 @@ except ImportError: from typing_extensions import Literal # 2.25. Arrival Board (arrivalBoard) -def boardArrival(accessId: str, +def board_arrival(accessId: str, json: bool = True ) -> dict: diff --git a/pyrmv/raw/boardDeparture.py b/pyrmv/raw/board_departure.py similarity index 90% rename from pyrmv/raw/boardDeparture.py rename to pyrmv/raw/board_departure.py index 2a4423a..499025b 100644 --- a/pyrmv/raw/boardDeparture.py +++ b/pyrmv/raw/board_departure.py @@ -8,7 +8,7 @@ except ImportError: from typing_extensions import Literal # 2.24. Departure Board (departureBoard) -def boardDeparture(accessId: str, +def board_departure(accessId: str, json: bool = True ) -> dict: diff --git a/pyrmv/raw/himSearch.py b/pyrmv/raw/him_search.py similarity index 98% rename from pyrmv/raw/himSearch.py rename to pyrmv/raw/him_search.py index 07cb8e8..1e0e957 100644 --- a/pyrmv/raw/himSearch.py +++ b/pyrmv/raw/him_search.py @@ -9,7 +9,7 @@ except ImportError: from typing_extensions import Literal # 2.37. HIM Search (himsearch) -def himSearch(accessId: str, +def him_search(accessId: str, json: bool = True, dateB: Union[str, datetime] = None, dateE: Union[str, datetime] = None, diff --git a/pyrmv/raw/journeyDetail.py b/pyrmv/raw/journey_detail.py similarity index 90% rename from pyrmv/raw/journeyDetail.py rename to pyrmv/raw/journey_detail.py index 216b52d..c5417a4 100644 --- a/pyrmv/raw/journeyDetail.py +++ b/pyrmv/raw/journey_detail.py @@ -8,7 +8,7 @@ except ImportError: from typing_extensions import Literal # 2.26. Journey Detail (journeyDetail) -def journeyDetail(accessId: str, +def journey_detail(accessId: str, json: bool = True ) -> dict: diff --git a/pyrmv/raw/stopByCoords.py b/pyrmv/raw/stop_by_coords.py similarity index 98% rename from pyrmv/raw/stopByCoords.py rename to pyrmv/raw/stop_by_coords.py index fe5bfde..40f24d2 100644 --- a/pyrmv/raw/stopByCoords.py +++ b/pyrmv/raw/stop_by_coords.py @@ -8,7 +8,7 @@ except ImportError: from typing_extensions import Literal # 2.4. Location Search by Coordinate (location.nearbystops) -def stopByCoords(accessId: str, +def stop_by_coords(accessId: str, originCoordLat: Union[str, float], originCoordLong: Union[str, float], lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en", diff --git a/pyrmv/raw/stopByName.py b/pyrmv/raw/stop_by_name.py similarity index 98% rename from pyrmv/raw/stopByName.py rename to pyrmv/raw/stop_by_name.py index 46f7bdc..84f6bf1 100644 --- a/pyrmv/raw/stopByName.py +++ b/pyrmv/raw/stop_by_name.py @@ -8,7 +8,7 @@ except ImportError: from typing_extensions import Literal # 2.3. Location Search by Name (location.name) -def stopByName(accessId: str, +def stop_by_name(accessId: str, inputString: str, lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en", json: bool = True, diff --git a/pyrmv/raw/findRoute.py b/pyrmv/raw/trip_find.py similarity index 99% rename from pyrmv/raw/findRoute.py rename to pyrmv/raw/trip_find.py index 17d9228..8f5187c 100644 --- a/pyrmv/raw/findRoute.py +++ b/pyrmv/raw/trip_find.py @@ -8,7 +8,7 @@ except ImportError: from typing_extensions import Literal # 2.12. Trip Search (trip) -def findRoute(accessId: str, +def trip_find(accessId: str, lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en", json: bool = True, diff --git a/pyrmv/raw/trip_recon.py b/pyrmv/raw/trip_recon.py new file mode 100644 index 0000000..0040f4c --- /dev/null +++ b/pyrmv/raw/trip_recon.py @@ -0,0 +1,32 @@ +from requests import get +from typing import List, Union +from xmltodict import parse as xmlparse + +try: + from typing import Literal +except ImportError: + from typing_extensions import Literal + +# 2.17. Reconstruction (recon) +def trip_recon(accessId: str, + json: bool = True + ) -> dict: + + if json: + headers = {"Accept": "application/json"} + else: + headers = {"Accept": "application/xml"} + + payload = {} + + for var, val in locals().items(): + if str(var) not in ["json", "headers", "payload"]: + if val != None: + payload[str(var)] = val + + output = get("https://www.rmv.de/hapi/recon", params=payload, headers=headers) + + if json: + return output.json() + else: + return xmlparse(output.content) \ No newline at end of file