class SensorHubService():
def __init__(self):
- self.version = '1.0'
+ self.version = '1.1'
self.errlog = None
def log(self, msg):
"""
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):