From: Pat Thoyts Date: Mon, 16 May 2016 11:58:05 +0000 (+0100) Subject: Support 'from' and 'until' parameters in the 'since' API call. X-Git-Url: http://privyetmir.co.uk/gitweb?a=commitdiff_plain;h=25c0d7e125575d098609164829e5769b6f5d3593;p=spd%2Fsensor-hub.git Support 'from' and 'until' parameters in the 'since' API call. --- diff --git a/sensor-hub.wsgi b/sensor-hub.wsgi index 9912063..4d09940 100755 --- a/sensor-hub.wsgi +++ b/sensor-hub.wsgi @@ -31,7 +31,7 @@ class RemoveKeyIterable(): class SensorHubService(): def __init__(self): - self.version = '1.0' + self.version = '1.1' self.errlog = None def log(self, msg): @@ -69,18 +69,22 @@ class SensorHubService(): """ try: cherrypy.response.headers['content-type'] = 'application/json' - param = cherrypy.request.params.get('when') - if not param is None: - when = dateparser.parse(param) - when = when.timestamp() + param_from = cherrypy.request.params.get('from') + param_until = cherrypy.request.params.get('until') + if not param_from is None: + when_from = dateparser.parse(param_from).timestamp() + else: + when_from = int(time() - (86400 * 7)) # 7 days ago + if not param_until is None: + when_until = dateparser.parse(param_until).timestamp() else: - when = int(time() - (86400 * 7)) # 7 days ago - data = self.get_since(when) + when_until = None + data = self.get_since(when_from, when_until) res = dict(response="ok", result=[x for x in data], version=self.version) except Exception as e: cherrypy.response.headers['content-type'] = 'application/json' self.log("error in \"since\": {0}".format(str(e))) - res = dict(response='error', message=str(e)) + res = dict(response='error', message=str(e), version=self.version) return res def get_since(self, when, until = None):