diff --git a/docs/source/conf.py b/docs/source/conf.py index 602425a..717b48e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -22,7 +22,7 @@ author = 'zaanposni' # The full version, including alpha/beta/rc tags -release = '1.0.0' +release = '1.1.0' # -- General configuration --------------------------------------------------- diff --git a/docs/source/requestreference.rst b/docs/source/requestreference.rst index 0380a37..5b863ae 100644 --- a/docs/source/requestreference.rst +++ b/docs/source/requestreference.rst @@ -7,14 +7,20 @@ Departures .. autofunction:: vvspy.get_departures +.. autofunction:: vvspy.get_departure + +.. autofunction:: vvspy.departures_now + Arrivals -------- .. autofunction:: vvspy.get_arrivals +.. autofunction:: vvspy.get_arrival Trips ----- .. autofunction:: vvspy.get_trips +.. autofunction:: vvspy.get_trip diff --git a/setup.py b/setup.py index 9f41e43..c9ab22f 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='vvspy', py_modules=["vvspy"], - version='1.0.0', + version='1.1.0', license='MIT', description='API Wrapper for VVS (Verkehrsverbund Stuttgart)', author='zaanposni', diff --git a/tests/run_tests.bat b/tests/run_tests.bat new file mode 100644 index 0000000..b9598a3 --- /dev/null +++ b/tests/run_tests.bat @@ -0,0 +1,2 @@ +@echo off +python start.py diff --git a/tests/run_tests.sh b/tests/run_tests.sh new file mode 100644 index 0000000..a323487 --- /dev/null +++ b/tests/run_tests.sh @@ -0,0 +1,2 @@ +#!/bin/bash +python3 start.py diff --git a/vvspy/__init__.py b/vvspy/__init__.py index 1d56dab..c4e27a9 100644 --- a/vvspy/__init__.py +++ b/vvspy/__init__.py @@ -4,10 +4,90 @@ from .obj import Arrival as __Arrival from .obj import Departure as __Departure +from .obj import Trip as __Trip from .trip import get_trips from .departures import get_departures from .arrivals import get_arrivals -def departures_now(station_id: __Union[str, int], limit: int = 100, **kwargs) -> __List[__Union[__Arrival, __Departure]]: +def departures_now(station_id: __Union[str, int], limit: int = 100, + **kwargs) -> __List[__Union[__Arrival, __Departure]]: + """ + Same as `get_departures` + But `datetime.datetime.now()` is already used as parameter. + + Returns: List[:class:`vvspy.obj.Departure`] + Returns none on webrequest errors or no results found. + + """ return get_departures(station_id=station_id, check_time=__datetime.now(), limit=limit, **kwargs) + + +def get_departure(station_id: __Union[str, int], check_time: __datetime = None, debug: bool = False, + request_params: dict = None, **kwargs) -> __Union[__Departure, None]: + """ + Same as `get_departures` + But limited to one obj as result. + + Returns: :class:`vvspy.obj.Departure` + Returns none on webrequest errors or no results found. + + """ + try: + return get_departures(station_id=station_id, check_time=check_time, limit=1, debug=debug, + request_params=request_params, **kwargs)[0] + except IndexError: # no results returned + if debug: + print("No departures found.") + return + except TypeError: # none returned | most likely an error + if debug: + print("Error on webrequest") + return + + +def get_arrival(station_id: __Union[str, int], check_time: __datetime = None, debug: bool = False, + request_params: dict = None, **kwargs) -> __Union[__Arrival, None]: + """ + Same as `get_arrivals` + But limited to one obj as result. + + Returns: :class:`vvspy.obj.Arrival` + Returns none on webrequest errors or no results found. + + """ + try: + return get_arrivals(station_id=station_id, check_time=check_time, limit=1, debug=debug, + request_params=request_params, **kwargs)[0] + except IndexError: # no results returned + if debug: + print("No arrivals found.") + return + except TypeError: # none returned | most likely an error + if debug: + print("Error on webrequest") + return + + +def get_trip(origin_station_id: __Union[str, int], destination_station_id: __Union[str, int], + check_time: __datetime = None, debug: bool = False, + request_params: dict = None, **kwargs) -> __Union[__Trip, None]: + """ + Same as `get_trips` + But limited to one obj as result. + + Returns: :class:`vvspy.obj.Trip` + Returns none on webrequest errors or no results found. + + """ + try: + return get_trips(origin_station_id=origin_station_id, destination_station_id=destination_station_id, + check_time=check_time, limit=1, debug=debug, request_params=request_params, **kwargs)[0] + except IndexError: # no results returned + if debug: + print("No trips found.") + return + except TypeError: # none returned | most likely an error + if debug: + print("Error on webrequest") + return