Mercurial > personal > weather-server
diff weather_server/server.py @ 23:88249e451566
server: show date when last report was >12h ago.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sun, 10 Nov 2019 19:42:04 -0500 |
parents | beb42c835c52 |
children | 7def5611895b |
line wrap: on
line diff
--- a/weather_server/server.py Fri Nov 01 00:48:56 2019 -0400 +++ b/weather_server/server.py Sun Nov 10 19:42:04 2019 -0500 @@ -55,11 +55,15 @@ date = tz.normalize(last_reading.sample_time.astimezone(tz)) else: date = None + now = datetime.datetime.now(tz=pytz.UTC) + diff = (now - date) if date else None + is_recent = diff and diff < datetime.timedelta(hours=12) return flask.render_template( 'location.html', location=loc, last_reading=last_reading, - date=date) + date=date, + date_format=f'%H:%M' if is_recent else '%Y-%m-%d %H:%M') @app.route('/<location>/recent') def recent(location: str):