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
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:

10
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"

2
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

Loading…
Cancel
Save