# Feedwise Plugin version 0.2+ats2 for Rawdog. # Ian Glover ian@manicai.net (modified somewhat by Adam Sampson) # # Sort articles into chunks by feed rather than date. # # The article_per_feed option can be specified in the config file to set the # maximum number of articles to show per feed. import rawdoglib.plugins class FeedwisePlugin: def __init__(self): self.last_feed = None # Scan the sorted list of articles and through away old ones to # so we don't exceed the configured limit. def limit_articles_per_feed(self, rawdog, config, articles): feed_counts = {} to_remove = [] for i in range(len(articles)): feed = articles[i].feed if feed not in feed_counts: feed_counts[feed] = 1 else: feed_counts[feed] = feed_counts[feed] + 1 if feed_counts[feed] > config.config.get("articles_per_feed", 50): # We don't want to from the list whilst iterating through it. # So use None as a marker for deletion. to_remove.append(articles[i]) for x in to_remove: articles.remove(x) return True # Sort the articles by feed and inside each feed by time. def sort_by_feed(self, rawdog, config, articles): def comparator(lhs, rhs): if cmp(lhs.feed, rhs.feed) != 0: return cmp(lhs.feed, rhs.feed) else: # Inverted as we want the most recent first. return -cmp(lhs.date, rhs.date) articles.sort(comparator) self.last_feed = None self.limit_articles_per_feed(rawdog, config, articles) return False # Split each feed into its own block. def write_divider(self, rawdog, config, f, article, date): feed = rawdog.feeds[article.feed] # Basic division header. basic_divider = '''