From 40513cc4883ea479e26e796eb6bc32d81ab69094 Mon Sep 17 00:00:00 2001 From: W1CDN Date: Sun, 9 Jul 2023 11:22:23 -0500 Subject: [PATCH] Use stations table on index.html. --- api_app.py | 13 ++++++++++++- kiss_and_db.py | 2 ++ templates/index.html | 10 ++++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/api_app.py b/api_app.py index bdb7504..26d899f 100644 --- a/api_app.py +++ b/api_app.py @@ -69,6 +69,17 @@ def select_all_frames(conn): rows = cur.fetchall() return rows +def select_all_stations(conn): + """ + Query all rows in the stations table + :param conn: the Connection object + :return: + """ + cur = conn.cursor() + cur.execute("SELECT * FROM stations ORDER BY last_heard_unix DESC") + rows = cur.fetchall() + return rows + def unique_stations(conn): """ Query all rows in the frames table @@ -109,7 +120,7 @@ def index(): response = json.loads(requests.get("https://digi.w1cdn.net/aprs_api/packets").text)['data'] # Play with function to create station list - stations = unique_stations(get_db_connection()) + stations = select_all_stations(get_db_connection()) return render_template('index.html', station_call = config['Settings']['station_call'], diff --git a/kiss_and_db.py b/kiss_and_db.py index d8e5320..b85fb8b 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -29,6 +29,7 @@ def main(): ki = aprs.TCPKISS(host=config['Settings']['kiss_host'], port=int(config['Settings']['kiss_port'])) ki.start() + # Make a simple frame and send it frame = aprs.APRSFrame.ui( destination="APZ001", @@ -72,6 +73,7 @@ def main(): # It's not immediately needed, so I'm skipping it. # Build query # "from" is wrappedin [] because it is a reserved word and using '' doesn't work. + # https://www.sqlite.org/lang_keywords.html try: station_update = "'"+a['from'] +"', '"+ str(a['created_unix']) +"', '1'" query3 = "INSERT INTO stations ([from], last_heard_unix, count) \ diff --git a/templates/index.html b/templates/index.html index daf22ad..7ba1ae7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -11,10 +11,10 @@ -

{{station_call}} Status

+

{{station_call}} Status

{{station_lat}}, {{station_lon}} -

Recent RF Packets

+

Recent RF Packets

@@ -36,8 +36,6 @@
from

Recent Stations

-Coming soon, see https://amiok.net/gitea/W1CDN/aprs_tool/issues/16. - @@ -48,8 +46,8 @@ Coming soon, see htt {% for i in stations %} - - + + {% endfor %}
from
{{ i['from'] }} {{ i['created'] }} {{ i['COUNT(id)']}} {{ i['last_heard_unix'] }} {{ i['count']}} aprs.fi