From 50e8324786737b44332b614bfda18b11bb0084c5 Mon Sep 17 00:00:00 2001 From: W1CDN Date: Sat, 26 Aug 2023 16:05:09 -0500 Subject: [PATCH] Show relative time. --- api_app.py | 10 ++++++++-- templates/index.html | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/api_app.py b/api_app.py index d0b0a2c..e7d0fd6 100644 --- a/api_app.py +++ b/api_app.py @@ -4,6 +4,7 @@ from datetime import date, timedelta import configparser import csv import datetime +import timeago import ast import glob import json, operator @@ -118,7 +119,11 @@ def index(): # Get list of recent packets using API # TODO use relative path - response = json.loads(requests.get("https://digi.w1cdn.net/aprs_api/packets").text)['data'] + frames = json.loads(requests.get("https://digi.w1cdn.net/aprs_api/packets").text)['data'] + for frame in frames: + if frame['created'] != None: + frame['time_ago'] = timeago.format(frame['created_unix'], datetime.datetime.now()) + # Play with function to create station list #stations = select_all_stations(get_db_connection()) @@ -129,12 +134,13 @@ def index(): for station in stations: if station['last_heard_unix'] != None: station['last_heard'] = datetime.datetime.utcfromtimestamp(station['last_heard_unix']) + station['time_ago'] = timeago.format(station['last_heard_unix'], datetime.datetime.now()) return render_template('index.html', station_call = config['Settings']['station_call'], station_lat = config['Settings']['station_lat'], station_lon = config['Settings']['station_lon'], - frames = response, + frames = frames, stations = stations) class Packets(Resource): diff --git a/templates/index.html b/templates/index.html index 9f3d900..6cfa01b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -21,6 +21,7 @@ object_name raw created (utc) + relative more {% for i in frames %} @@ -29,6 +30,7 @@ {{ i['object_name'] }} {{ i['raw'] }} {{ i['created'] }} + {{ i['time_ago'] }} query, aprs.fi @@ -40,6 +42,7 @@ from last heard (utc) + relative count more @@ -47,6 +50,7 @@ {{ i['from'] }} {{ i['last_heard'] }} + {{ i['time_ago'] }} {{ i['count']}} aprs.fi