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