Only select 10 stations by default.

This commit is contained in:
W1CDN 2024-11-20 10:52:58 -06:00
parent ab595ed3cb
commit c8f8f28a4a

View File

@ -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