Order by created date in db call.

This commit is contained in:
W1CDN 2023-04-25 14:19:29 -05:00
parent ab850a76a3
commit f396fe87af

View File

@ -70,7 +70,7 @@ def select_frames(conn, n, from_):
# Workaround to deal with missing value in WHERE # Workaround to deal with missing value in WHERE
from_ = "IS NOT NULL" if from_ == None else "='"+from_+"'" from_ = "IS NOT NULL" if from_ == None else "='"+from_+"'"
#sql = "SELECT * FROM frames LIMIT "+n #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) print(sql)
cur.execute(sql) cur.execute(sql)
rows = cur.fetchall() rows = cur.fetchall()
@ -89,15 +89,12 @@ class Packets(Resource):
# Limit to number of records requested # Limit to number of records requested
data = select_frames(conn, n = n, from_ = from_) data = select_frames(conn, n = n, from_ = from_)
# Sort by created date, descending (https://stackoverflow.com/a/45266808) # Sort by created date, descending (https://stackoverflow.com/a/45266808)
data.sort(key=operator.itemgetter('created'), reverse=True) #data.sort(key=operator.itemgetter('created'), reverse=True)
#data.sort(key=created, reverse=True)
return {'data': data}, 200 # return data and 200 OK code return {'data': data}, 200 # return data and 200 OK code
# Read config # Read config
config = read_config() config = read_config()
log_folder = config['Settings']['log_folder'] 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 # Start subprocess to watch KISS connection
import subprocess import subprocess