diff --git a/system_module/db.py b/system_module/db.py index 4723c2b..c0e9042 100644 --- a/system_module/db.py +++ b/system_module/db.py @@ -3,6 +3,7 @@ import os import json from collections import Counter import gelbooru +from datetime import datetime class DB: def __init__(self): @@ -41,7 +42,15 @@ class DB: pass def get_all(self): - return self.db.all() + sorted_records = sorted( + self.db.all(), + key=lambda x: datetime.strptime( + x["timestamp"], + "%a %b %d %H:%M:%S %z %Y" + ), + reverse=True + ) + return sorted_records def get_search(self, ratings, tags): ratings @@ -49,7 +58,15 @@ class DB: self.File.rating.one_of(self.ratings) & self.File.tags.any(self.tags) ) - return results + sorted_records = sorted( + results, + key=lambda x: datetime.strptime( + x["timestamp"], + "%a %b %d %H:%M:%S %z %Y" + ), + reverse=True + ) + return sorted_records def get_unknow(self): results = self.db.search(self.File.tags == [])