#!/usr/bin/python import feedparser from datetime import datetime, timedelta from plugins import Notification class Feed(object): def __init__(self, url): self.url = url self.data = None self.seen = list() def get_title(self): return self.data.feed.title def update(self): self.data = feedparser.parse(self.url) new_items = False for e in self.data.entries: if (e.id, e.date) not in self.seen: new_items = True break return new_items def get_entries(self): # Get entries for e in self.data.entries: if (e.id, e.date) not in self.seen: self.seen.append((e.id, e.date)) line = " - " + e.title try: line += " (" + e.author + ")" except Exception: pass line += " View" yield line # Remove read entries if necessary if len(self.seen) > len(self.data.entries): self.seen.pop(0) class FeedNotifier(object): def __init__(self): self.feeds = list() self.update_freq = 10 self.last_update = datetime.now() self.force_update = True self.load_feeds() def load_feeds(self): f = open("feeds") for l in f.readlines(): self.feeds.append(Feed(l)) def update(self): print "updating feeds..." for f in self.feeds: if f.update(): print " *", f.get_title() n = Notification(f.get_title()) for e in f.get_entries(): n.body_append(e + "\n") yield n print "done" def new_round(self): if (datetime.now() - self.last_update) < timedelta(minutes=self.update_freq) and not self.force_update: return self.force_update = False self.last_update = datetime.now() for i in self.update(): yield i