You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.9 KiB
67 lines
1.9 KiB
import json
|
|
import random
|
|
from datetime import datetime
|
|
from time import mktime
|
|
|
|
from parse_rss_feeds import parse_rss_feeds
|
|
|
|
|
|
class Column(object):
|
|
def __init__(self, title, urls):
|
|
self.title = title
|
|
self.urls = urls
|
|
self.limit = None
|
|
self.sort_order = None
|
|
self.entries = None
|
|
self.tag_filter = None
|
|
|
|
def set_tag_filter(self, tag_filter):
|
|
self.tag_filter = tag_filter
|
|
|
|
def set_sort_order(self, sort_order):
|
|
self.sort_order = sort_order
|
|
|
|
def set_limit(self, limit):
|
|
self.limit = limit
|
|
|
|
def set_entries(self, entries):
|
|
self.entries = entries
|
|
|
|
def set_title(self, title):
|
|
self.title = title
|
|
|
|
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":
|
|
random.shuffle(entrylist)
|
|
self.entries = dict(entrylist)
|
|
return
|
|
if self.sort_order.lower() == "chronological":
|
|
entrylist.sort(
|
|
key=lambda x: datetime.fromtimestamp(mktime(x[1][1]))
|
|
)
|
|
self.entries = dict(entrylist)
|
|
return
|
|
if self.sort_order.lower() == "reverse-chronological":
|
|
entrylist.sort(
|
|
key=lambda x: datetime.fromtimestamp(mktime(x[1][1]))
|
|
)
|
|
entrylist.reverse()
|
|
self.entries = dict(entrylist)
|
|
return
|
|
|
|
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.tag_filter)
|
|
self.entries = entries
|
|
if self.sort_order:
|
|
self._sort_by_order()
|
|
if self.limit:
|
|
self._enforce_limit()
|
|
|