From 6cc4bfdf8d67029b5038693dc99c27e669d0234c Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Fri, 1 Nov 2013 15:33:36 +0100 Subject: It is now possible to add a feed via a form for different users. --- pyaggr3g470r/feedgetter.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'pyaggr3g470r/feedgetter.py') diff --git a/pyaggr3g470r/feedgetter.py b/pyaggr3g470r/feedgetter.py index bae0cb8b..2b0c08f9 100644 --- a/pyaggr3g470r/feedgetter.py +++ b/pyaggr3g470r/feedgetter.py @@ -50,23 +50,23 @@ class FeedGetter(object): This class uses feedparser module from Mark Pilgrim. For each feed a new thread is launched. """ - def __init__(self): + def __init__(self, email): """ Initializes the database connection. """ #feedparser.USER_AGENT = conf.USER_AGENT feedparser.USER_AGENT = "pyAggr3g470r" + self.user = models.User.objects(email=email).first() def retrieve_feed(self): """ Parse the file 'feeds.lst' and launch a thread for each RSS feed. """ - feeds = models.Feed.objects() - for feed in feeds: + for feed in self.user.feeds: try: # launch a new thread for the RSS feed thread = threading.Thread(None, self.process, \ - None, (feed,)) + None, (feed, )) thread.start() list_of_threads.append(thread) except: @@ -88,8 +88,7 @@ class FeedGetter(object): articles = [] for article in a_feed['entries']: - exist = models.Article.objects(link=article.link).first() - if exist != None: + if article.link in [farticle.link for farticle in feed.articles]: continue description = "" @@ -137,7 +136,8 @@ class FeedGetter(object): """ feed.articles.extend(articles) feed.articles = sorted(feed.articles, key=lambda t: t.date, reverse=True) - feed.save() + #feed.save() + self.user.save() if __name__ == "__main__": -- cgit