From 5793e57aa9d25edee118785f19a66b5dd4ea8642 Mon Sep 17 00:00:00 2001 From: W1CDN Date: Sun, 16 Apr 2023 16:59:09 -0500 Subject: [PATCH] Sort /packets descending by created. --- api_app.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api_app.py b/api_app.py index 338662b..b4f3da8 100644 --- a/api_app.py +++ b/api_app.py @@ -5,7 +5,7 @@ import configparser import csv import ast import glob -import json +import json, operator import sqlite3 api_app = Flask(__name__) api = Api(api_app) @@ -51,7 +51,6 @@ def dict_factory(cursor, row): def get_db_connection(): conn = sqlite3.connect('database.db') - #conn.row_factory = sqlite3.Row conn.row_factory = dict_factory return conn @@ -71,6 +70,9 @@ class Packets(Resource): #data = read_logs(log_folder) conn = get_db_connection() data = select_all_frames(conn) + # Sort by created date, descending (https://stackoverflow.com/a/45266808) + data.sort(key=operator.itemgetter('created'), reverse=True) + #data.sort(key=created, reverse=True) return {'data': data}, 200 # return data and 200 OK code # Read config