From f396fe87af0288e6e57810065945dfb6cec7e45c Mon Sep 17 00:00:00 2001 From: W1CDN Date: Tue, 25 Apr 2023 14:19:29 -0500 Subject: [PATCH] Order by created date in db call. --- api_app.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/api_app.py b/api_app.py index 427680e..4f64710 100644 --- a/api_app.py +++ b/api_app.py @@ -70,7 +70,7 @@ def select_frames(conn, n, from_): # Workaround to deal with missing value in WHERE from_ = "IS NOT NULL" if from_ == None else "='"+from_+"'" #sql = "SELECT * FROM frames LIMIT "+n - sql = 'SELECT * FROM frames WHERE "from" {from_} LIMIT {n}'.format(from_=from_, n=n) + sql = 'SELECT * FROM frames WHERE "from" {from_} ORDER BY created DESC LIMIT {n}'.format(from_=from_, n=n) print(sql) cur.execute(sql) rows = cur.fetchall() @@ -89,15 +89,12 @@ class Packets(Resource): # Limit to number of records requested data = select_frames(conn, n = n, from_ = from_) # Sort by created date, descending (https://stackoverflow.com/a/45266808) - data.sort(key=operator.itemgetter('created'), reverse=True) - #data.sort(key=created, reverse=True) + #data.sort(key=operator.itemgetter('created'), reverse=True) return {'data': data}, 200 # return data and 200 OK code # Read config config = read_config() log_folder = config['Settings']['log_folder'] -# Load logs first (just to check for errors before page loads) -#data = read_logs(log_folder) # Start subprocess to watch KISS connection import subprocess