From e10c0eed09273fd51268bf80e8956e37438580af Mon Sep 17 00:00:00 2001 From: zaanposni Date: Sun, 15 Dec 2019 10:42:48 +0100 Subject: [PATCH 1/4] added functions to get only on result --- docs/source/requestreference.rst | 6 +++ vvspy/__init__.py | 82 +++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) 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/vvspy/__init__.py b/vvspy/__init__.py index 1d56dab..bac2650 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 From 694fdc20ef66544bc954771f199db159b8900436 Mon Sep 17 00:00:00 2001 From: zaanposni Date: Sun, 15 Dec 2019 10:43:01 +0100 Subject: [PATCH 2/4] added scripts to run unittests --- tests/run_tests.bat | 2 ++ tests/run_tests.sh | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 tests/run_tests.bat create mode 100644 tests/run_tests.sh 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 From 56e5f7993dabf5f5a5b9ffbd82e0708617fe5f10 Mon Sep 17 00:00:00 2001 From: zaanposni Date: Sun, 15 Dec 2019 10:47:13 +0100 Subject: [PATCH 3/4] minor bug fix --- vvspy/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vvspy/__init__.py b/vvspy/__init__.py index bac2650..c4e27a9 100644 --- a/vvspy/__init__.py +++ b/vvspy/__init__.py @@ -43,7 +43,7 @@ def get_departure(station_id: __Union[str, int], check_time: __datetime = None, except TypeError: # none returned | most likely an error if debug: print("Error on webrequest") - return + return def get_arrival(station_id: __Union[str, int], check_time: __datetime = None, debug: bool = False, @@ -66,7 +66,7 @@ def get_arrival(station_id: __Union[str, int], check_time: __datetime = None, de except TypeError: # none returned | most likely an error if debug: print("Error on webrequest") - return + return def get_trip(origin_station_id: __Union[str, int], destination_station_id: __Union[str, int], @@ -90,4 +90,4 @@ def get_trip(origin_station_id: __Union[str, int], destination_station_id: __Uni except TypeError: # none returned | most likely an error if debug: print("Error on webrequest") - return + return From bdb83cad86c84b78c0f76e92626c1197a0bc3c66 Mon Sep 17 00:00:00 2001 From: zaanposni Date: Sun, 15 Dec 2019 10:48:33 +0100 Subject: [PATCH 4/4] bumped version --- docs/source/conf.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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',