Browse Source

made sort orders

main
crunk 1 year ago
parent
commit
1aa99618aa
  1. 25
      column.py
  2. 10
      columns.toml
  3. 2
      parse_rss_feeds.py

25
column.py

@ -1,4 +1,5 @@
import random import random
from datetime import datetime
from parse_rss_feeds import parse_rss_feeds from parse_rss_feeds import parse_rss_feeds
@ -17,10 +18,32 @@ class Column:
self.limit = limit self.limit = limit
def _sort_by_order(self): def _sort_by_order(self):
if self.sort_order.lower() == "random":
entrylist = list(self.entries.items()) entrylist = list(self.entries.items())
if self.sort_order.lower() == "reverse":
entrylist.reverse()
self.entries = dict(entrylist)
return
if self.sort_order.lower() == "random":
random.shuffle(entrylist) random.shuffle(entrylist)
self.entries = dict(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): def _enforce_limit(self):
while len(self.entries) > self.limit: while len(self.entries) > self.limit:

10
columns.toml

@ -1,14 +1,10 @@
[[column]] [[column]]
urls = ["https://varia.zone/logs/x-y/feed.rss.xml","https://varia.zone/logs/x-y-protocols/feed.rss.xml"] urls = ["https://varia.zone/logs/x-y/feed.rss.xml","https://varia.zone/logs/x-y-protocols/feed.rss.xml"]
title = "code" title = "code"
limit = 20 limit = 40
sort_order = "random" sort_order = "random"
[[column]] [[column]]
urls = ["https://post.lurk.org/@cmos4040.rss"] urls = ["https://post.lurk.org/@cmos4040.rss","https://post.lurk.org/tags/radio.rss"]
title = "circulations" title = "circulations"
sort_order = "reverse-chronological"
[[column]]
urls = ["https://a-nourishing-network.radical-openness.org/feeds/feed.rss"]
title = "a-nourishing-network"
limit = 20

2
parse_rss_feeds.py

@ -14,7 +14,7 @@ def _parse_single_rss_feed(url, entries):
entries[title] = [] entries[title] = []
entrylist = entries[title] entrylist = entries[title]
entrylist.append(entry.description) entrylist.append(entry.description)
entrylist.append(entry.published)
return entries return entries

Loading…
Cancel
Save