Mercurial > personal > weather-server
changeset 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 | e229afdd447b |
children | 20c8ec56e447 |
files | setup.py weather_server/server.py weather_server/templates/location.html |
diffstat | 3 files changed, 9 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/setup.py Fri Nov 01 00:48:56 2019 -0400 +++ b/setup.py Sun Nov 10 19:42:04 2019 -0500 @@ -2,7 +2,7 @@ setuptools.setup( name='weather-server', - version='0.0.7', + version='0.0.8', packages=setuptools.find_packages(), python_requires='>=3.7', install_requires=[
--- 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):
--- a/weather_server/templates/location.html Fri Nov 01 00:48:56 2019 -0400 +++ b/weather_server/templates/location.html Sun Nov 10 19:42:04 2019 -0500 @@ -36,7 +36,9 @@ <p id="timestamp"> <span> <span class="key">Reported</span> - <span class="value">{{ "{:%H:%M}".format(date) }}</span> + <span class="value"> + {{- "{date:{fmt}}".format(date=date, fmt=date_format) -}} + </span> </span> </p> {% else %}