Skip to content

Commit

Permalink
Merge pull request #46 from FI18-Trainees/zaanposni-patch-1
Browse files Browse the repository at this point in the history
added function to get only on result obj
  • Loading branch information
zaanposni authored Dec 15, 2019
2 parents 9a968a8 + bdb83ca commit a0246bf
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'zaanposni'

# The full version, including alpha/beta/rc tags
release = '1.0.0'
release = '1.1.0'


# -- General configuration ---------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions docs/source/requestreference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions tests/run_tests.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
python start.py
2 changes: 2 additions & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
python3 start.py
82 changes: 81 additions & 1 deletion vvspy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a0246bf

Please sign in to comment.