Support 'from' and 'until' parameters in the 'since' API call.
authorPat Thoyts <patthoyts@users.sourceforge.net>
Mon, 16 May 2016 11:58:05 +0000 (12:58 +0100)
committerPat Thoyts <patthoyts@users.sourceforge.net>
Mon, 16 May 2016 11:58:05 +0000 (12:58 +0100)
sensor-hub.wsgi

index 991206359bd3208cef5572ddf87f58c5f95ce8d5..4d09940196eb879b046c897059d77f9a5e15be75 100755 (executable)
@@ -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):