36 lines
946 B
Python
36 lines
946 B
Python
import random
|
|
from parse_rss_feeds import parse_rss_feeds
|
|
|
|
|
|
class Column:
|
|
def __init__(self, title, urls):
|
|
self.title = title
|
|
self.urls = urls
|
|
self.entries = None
|
|
self.sort_order = None
|
|
self.limit = None
|
|
|
|
def set_sort_order(self, sort_order):
|
|
self.sort_order = sort_order
|
|
|
|
def set_limit(self, limit):
|
|
self.limit = limit
|
|
|
|
def _sort_by_order(self):
|
|
if self.sort_order.lower() == "random":
|
|
entrylist = list(self.entries.items())
|
|
random.shuffle(entrylist)
|
|
self.entries = dict(entrylist)
|
|
|
|
def _enforce_limit(self):
|
|
while len(self.entries) > self.limit:
|
|
self.entries.popitem()
|
|
|
|
def load_content_from_feeds(self):
|
|
entries = parse_rss_feeds(self.urls)
|
|
self.entries = entries
|
|
if self.sort_order:
|
|
self._sort_by_order()
|
|
if self.limit:
|
|
self._enforce_limit()
|