Only select 10 stations by default.
This commit is contained in:
parent
ab595ed3cb
commit
c8f8f28a4a
15
api_app.py
15
api_app.py
|
@ -86,6 +86,19 @@ def select_frames(conn, n, url_params):
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user