- bvggrabber.api.compute_remaining(start, end)[source]¶
Compute the number of seconds between start and end and return the number of seconds rounded down to entire minutes. That means:
- [0, 59] => 0
- [60, 119] => 60
- [120, 179] => 120
- [-59, -1] => -60
- [-119, -60] => -120
Parameters:
- start (datetime.datetime) – The start to compute the remaining number of minutes.
- end (datetime.datetime) – The end of the interval
Raises: TypeError if either of start or end is not a datetime.datetime.
Returns: The number of remaining seconds rounded to entire minutes
Return type: int
- class bvggrabber.api.Departure(start, end, when, line, since=None, no_add_day=False)[source]¶
- __eq__(other)[source]¶
Two departures are assumed to be equal iff their remaining time and their destination are equal.
Right now we do not considering the start or line, since that would require some kind of geo location in order to define a total order.
- __init__(start, end, when, line, since=None, no_add_day=False)[source]¶
Parameters:
- start (str) – The start station
- end (str) – The end station
- when – The leaving time of the public transport at the given start station. Might be an int (timestamp), a datetime.datetime instance or a str accepted by dateutil.parse(). If when is smaller than since and the difference between both times is larger than 12 hours (43200sec), the API will add another day unless no_add_day is True.
- line (str) – The line of the public transport
- since – Either None or datetime.datetime. Defines the temporal start for searching. None will internally be resolved as datetime.datetime.now().
- no_add_day (bool) – If true, there no additional day will be added if when is smaller than since. Default False.
Raises: TypeError if when is invalid or cannot be parsed.
- class bvggrabber.api.Response(state, station=None, departures=None, error=None)[source]¶
- __init__(state, station=None, departures=None, error=None)[source]¶
Creates a new response. Returned by QueryApi.call()
Parameters:
- state (bool) – True iff the request and parsing was successful, False otherwise.
- station – If a list, the station name is ambiguous. If a string the full qualified name of the station.
- departures – A list of Departure` objects
- error (Exception) – In case an unexpected error occurred, this contains the original exception.
If state is True, station must be a str and departures must be a list of Departure` objects. If state is False there must be several reasons for that:
- The provided station name during the QueryApi.call() returned multiple possible departing stations. You have to specify the name in an unambiguous way.
- The station does not exist at all.
- An exception occurred during the QueryApi.call()
Deprecated since version 0.1b3: The state argument will be removed in the future and will be computed automatically based on station, departures and error.
- departures[source]¶
A list of 2-tuple in the form (str, Departure). The first element in the tuple defines the departing station where the second element holds a list of departure objects.
- json[source]¶
Uses ObjectJSONEncoder to encode the departures to a JSON format.
- merge(other)[source]¶
Checks that other is a Response and extends departures by the departures given in other iff neither response object has a invalid state.