changeset 2:cda47993a193

server: fix bugs and improve template.
author Paul Fisher <paul@pfish.zone>
date Sun, 29 Sep 2019 01:18:18 -0400
parents f66df122f18d
children b42c4bfe57c7
files weather_server/server.py weather_server/templates/location.html
diffstat 2 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/weather_server/server.py	Sun Sep 29 00:52:13 2019 -0400
+++ b/weather_server/server.py	Sun Sep 29 01:18:18 2019 -0400
@@ -25,7 +25,7 @@
         if not target:
             flask.abort(404)
         try:
-            target_loc = locs.get(target)
+            target_loc, logger = locs.get(target)
         except KeyError:
             flask.abort(404)
 
@@ -43,8 +43,8 @@
             )
             for item in reader
         ]
-        target_loc.logger.write_rows(entries)
-        return {'status': 'OK'}
+        logger.write_rows(entries)
+        return flask.jsonify({'status': 'OK'})
 
     @app.route('/<location>')
     def show(location):
@@ -55,7 +55,7 @@
         data = logger.data
         if data:
             last_reading = data[-1]
-            tz = loc.timezone
+            tz = loc.timezone()
             date = tz.normalize(last_reading.sample_time.astimezone(tz))
         else:
             last_reading = None
--- a/weather_server/templates/location.html	Sun Sep 29 00:52:13 2019 -0400
+++ b/weather_server/templates/location.html	Sun Sep 29 01:18:18 2019 -0400
@@ -6,7 +6,8 @@
     <body>
         {% if last_reading %}
             Temperature: {{ last_reading.temp_f }}<br>
-            Dew point: {{ last_reading.dew_point_f }}
+            Dew point: {{ last_reading.dew_point_f }}<br>
+            As of: {{ date }}
         {% else %}
             No weather yet
         {% endif %}