diff options
Diffstat (limited to 'bvggrabber/api/__init__.py')
-rw-r--r-- | bvggrabber/api/__init__.py | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/bvggrabber/api/__init__.py b/bvggrabber/api/__init__.py index c489e8b..3cd1239 100644 --- a/bvggrabber/api/__init__.py +++ b/bvggrabber/api/__init__.py @@ -9,6 +9,7 @@ from math import floor from dateutil.parser import parse from bvggrabber.utils.format import fullformat, timeformat +from bvggrabber.utils.json import ObjectJSONEncoder def compute_remaining(start, end): @@ -32,9 +33,9 @@ class QueryApi(object): class Response(object): - def __init__(self, state, departures, error=None): + def __init__(self, state, station=None, departures=None, error=None): self._state = state - self._departures = departures + self._departures = [(station, departures)] self._error = error def merge(self, other): @@ -49,6 +50,10 @@ class Response(object): raise TypeError("The given object is not a response object") @property + def to_json(self): + return ObjectJSONEncoder(ensure_ascii=False).encode(self.departures) + + @property def state(self): return self._state @@ -88,18 +93,7 @@ class Departure(object): @property def remaining(self): - return compute_remaining(self.now, self.when) - - @property - def to_json(self): - return json.dumps({'start': self.start, - 'end': self.end, - 'line': self.line, - 'now_full': fullformat(self.now), - 'now_hour': timeformat(self.now), - 'when_full': fullformat(self.when), - 'when_hour': timeformat(self.when), - 'remaining': round(self.remaining)}) + return int(compute_remaining(self.now, self.when)) def __eq__(self, other): """Two departures are assumed to be equal iff their remaining time |