From: Pat Thoyts Date: Tue, 17 May 2016 22:53:12 +0000 (+0100) Subject: Support either ISO or time_t dates for download. X-Git-Url: https://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=c8b602de0defbe59111ae3221c6c4c15e976fe1a;p=spd%2Fsensor-hub.git Support either ISO or time_t dates for download. --- diff --git a/sensor-hub.wsgi b/sensor-hub.wsgi index 4d09940..6009057 100755 --- a/sensor-hub.wsgi +++ b/sensor-hub.wsgi @@ -120,6 +120,14 @@ class SensorHubService(): result = sorted(groups, key=len, reverse=True)[0] return {'response': result, 'version': self.version} + def parse_time(self, str): + """Parse a time, either as unix time or a ISO timestamp""" + try: + return int(str) + except ValueError: + return int(dateparser.parse(str).timestamp()) + + def get_ascii(self, data): @cherrypy.expose def download(self, *args, **kwargs): try: @@ -128,7 +136,9 @@ class SensorHubService(): if param_from is None or param_until is None: raise Exception("must provide both from and to parameters") else: - data = self.get_since(int(param_from), int(param_until)) + param_from = self.parse_time(param_from) + param_until = self.parse_time(param_until) + data = self.get_since(param_from, param_until) if cherrypy.request.params.get('type') == 'text': cherrypy.response.headers['content-type'] = 'text/plain' raise Exception("not implemented") diff --git a/static/sensor-hub.html b/static/sensor-hub.html index 801efa5..4574e37 100644 --- a/static/sensor-hub.html +++ b/static/sensor-hub.html @@ -1,4 +1,4 @@ - + @@ -70,8 +70,8 @@ function weekend_markings(axes) { } function on_download(mimetype) { - if (document.custom.graph) { - var axes = document.custom.graph.getAxes() + if (document.custom.graph_main) { + var axes = document.custom.graph_main.plot.getAxes() var upper = parseInt(axes.xaxis.max / 1000); var lower = parseInt(axes.xaxis.min / 1000); var url = 'download?type=' + mimetype + '&from=' + lower + '&to=' + upper;