From 1aa99618aa4d4c124814865598cdb7ac611afd07 Mon Sep 17 00:00:00 2001 From: crunk Date: Sat, 3 Jun 2023 22:07:18 +0200 Subject: [PATCH] made sort orders --- column.py | 25 ++++++++++++++++++++++++- columns.toml | 10 +++------- parse_rss_feeds.py | 2 +- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/column.py b/column.py index 192a9be..6d0101d 100644 --- a/column.py +++ b/column.py @@ -1,4 +1,5 @@ import random +from datetime import datetime from parse_rss_feeds import parse_rss_feeds @@ -17,10 +18,32 @@ class Column: self.limit = limit def _sort_by_order(self): + entrylist = list(self.entries.items()) + if self.sort_order.lower() == "reverse": + entrylist.reverse() + self.entries = dict(entrylist) + return if self.sort_order.lower() == "random": - entrylist = list(self.entries.items()) random.shuffle(entrylist) self.entries = dict(entrylist) + return + if self.sort_order.lower() == "chronological": + entrylist.sort( + key=lambda x: datetime.strptime( + x[1][1], "%a, %d %b %Y %H:%M:%S %z" + ) + ) + self.entries = dict(entrylist) + return + if self.sort_order.lower() == "reverse-chronological": + entrylist.sort( + key=lambda x: datetime.strptime( + x[1][1], "%a, %d %b %Y %H:%M:%S %z" + ) + ) + entrylist.reverse() + self.entries = dict(entrylist) + return def _enforce_limit(self): while len(self.entries) > self.limit: diff --git a/columns.toml b/columns.toml index b7e29c7..23d10ce 100644 --- a/columns.toml +++ b/columns.toml @@ -1,14 +1,10 @@ [[column]] urls = ["https://varia.zone/logs/x-y/feed.rss.xml","https://varia.zone/logs/x-y-protocols/feed.rss.xml"] title = "code" -limit = 20 +limit = 40 sort_order = "random" [[column]] -urls = ["https://post.lurk.org/@cmos4040.rss"] +urls = ["https://post.lurk.org/@cmos4040.rss","https://post.lurk.org/tags/radio.rss"] title = "circulations" - -[[column]] -urls = ["https://a-nourishing-network.radical-openness.org/feeds/feed.rss"] -title = "a-nourishing-network" -limit = 20 +sort_order = "reverse-chronological" diff --git a/parse_rss_feeds.py b/parse_rss_feeds.py index 331dfc4..824ae8d 100644 --- a/parse_rss_feeds.py +++ b/parse_rss_feeds.py @@ -14,7 +14,7 @@ def _parse_single_rss_feed(url, entries): entries[title] = [] entrylist = entries[title] entrylist.append(entry.description) - + entrylist.append(entry.published) return entries