From c8f8f28a4ac86dde5bd9d6c25dbc4760b17f6b08 Mon Sep 17 00:00:00 2001 From: W1CDN Date: Wed, 20 Nov 2024 10:52:58 -0600 Subject: [PATCH] Only select 10 stations by default. --- api_app.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/api_app.py b/api_app.py index fb35a98..de0a777 100644 --- a/api_app.py +++ b/api_app.py @@ -85,6 +85,19 @@ def select_frames(conn, n, url_params): cur.execute(sql) rows = cur.fetchall() return rows + +def select_stations(conn, n): + """ + Query rows in the stations table + :param conn: the Connection object + :return: + """ + cur = conn.cursor() + sql = 'SELECT * FROM stations ORDER BY last_heard_unix DESC LIMIT {n}'.format(n=n) + print(sql) + cur.execute(sql) + rows = cur.fetchall() + return rows @api_app.route('/') def index(): @@ -215,7 +228,7 @@ class Stations(Resource): conn = get_db_connection() # Limit to number of records requested - data = select_all_stations(conn) + data = select_stations(conn, n = n) # Sort by created date, descending (https://stackoverflow.com/a/45266808) #data.sort(key=operator.itemgetter('created'), reverse=True) return {'data':data}, 200 # return data and 200 OK code