Beispiel #1
0
    def fetch(self):
        parsed_feed = feedparser.parse(self.url)
        self.title = safe_unicode(parsed_feed.channel.title)
        self.description = safe_unicode(parsed_feed.channel.description)
        print 'description:'
        print safe_unicode(parsed_feed.channel.description)
        self.link = safe_unicode(parsed_feed.feed.link)
        self.version = parsed_feed.version
        self.encoding = parsed_feed.encoding
        if not self.last_checked:
            self.last_checked = datetime.datetime(1980, 1, 1)
        self.save()
        for entry in parsed_feed.entries:
            entry_date = datetime.datetime.fromtimestamp(
                mktime(entry.date_parsed))
            entry_updated = datetime.datetime.fromtimestamp(
                mktime(entry.updated_parsed))
            if entry_updated > self.last_checked:
                updated = False
                new = False
                try:
                    feed_entry = FeedEntry.objects.get(link=entry.link)
                    if entry_updated > self.last_checked:
                        updated = True
                except FeedEntry.DoesNotExist:
                    new = True
                    feed_entry = FeedEntry()
                if updated or new:
                    feed_entry.feed = self
                    feed_entry.populate_from_parsed_feed_entry(entry)
                    feed_entry.save()
                if updated:
                    ## go mark all the items as unread for users
                    UserEntry.objects.filter(entry=feed_entry).update(
                        read=False)
                if new:
                    ## go add to user's feeds
                    user_categories = UserCategory.objects.filter(feeds=self)
                    for user_cat in user_categories:
                        user_entry = UserEntry()
                        user_entry.user = user_cat.user
                        user_entry.entry = feed_entry
                        user_entry.save()

        self.last_checked = datetime.datetime.now()
        self.save()
Beispiel #2
0
 def fetch(self):
     parsed_feed = feedparser.parse(self.url)
     self.title = safe_unicode(parsed_feed.channel.title)
     self.description = safe_unicode(parsed_feed.channel.description)
     print 'description:'
     print safe_unicode(parsed_feed.channel.description)
     self.link = safe_unicode(parsed_feed.feed.link)
     self.version = parsed_feed.version
     self.encoding = parsed_feed.encoding
     if not self.last_checked:
         self.last_checked = datetime.datetime(1980,1,1)
     self.save()
     for entry in parsed_feed.entries:
         entry_date = datetime.datetime.fromtimestamp(mktime(entry.date_parsed))
         entry_updated = datetime.datetime.fromtimestamp(mktime(entry.updated_parsed))
         if entry_updated > self.last_checked:
             updated = False
             new = False
             try:
                 feed_entry = FeedEntry.objects.get(link=entry.link)
                 if entry_updated > self.last_checked:
                     updated = True
             except FeedEntry.DoesNotExist:
                 new = True
                 feed_entry = FeedEntry()
             if updated or new:
                 feed_entry.feed = self
                 feed_entry.populate_from_parsed_feed_entry(entry)
                 feed_entry.save()
             if updated:
                 ## go mark all the items as unread for users
                 UserEntry.objects.filter(entry = feed_entry).update(read=False)
             if new:
                 ## go add to user's feeds
                 user_categories = UserCategory.objects.filter(feeds=self)
                 for user_cat in user_categories:
                     user_entry = UserEntry()
                     user_entry.user = user_cat.user
                     user_entry.entry = feed_entry
                     user_entry.save()
                 
     self.last_checked = datetime.datetime.now()
     self.save()
Beispiel #3
0
 def populate_from_parsed_feed_entry(self,feed_entry):
     self.link = safe_unicode(feed_entry.link)
     self.title = safe_unicode(feed_entry.title)
     try:
         self.author = safe_unicode(feed_entry.author)
     except:
         pass
     self.summary_detail = safe_unicode(feed_entry.summary_detail.value)
     try:
         self.description = safe_unicode(feed_entry.description)
         print 'link'
         print self.link
         print 'description:'
         print safe_unicode(feed_entry.description)
     except:
         pass
     self.date_published = datetime.datetime.fromtimestamp(mktime(feed_entry.date_parsed))
     try:
         self.date_updated = datetime.datetime.fromtimestamp(mktime(feed_entry.updated_parsed))
     except:
         self.date_updated = self.date_published 
Beispiel #4
0
 def populate_from_parsed_feed_entry(self, feed_entry):
     self.link = safe_unicode(feed_entry.link)
     self.title = safe_unicode(feed_entry.title)
     try:
         self.author = safe_unicode(feed_entry.author)
     except:
         pass
     self.summary_detail = safe_unicode(feed_entry.summary_detail.value)
     try:
         self.description = safe_unicode(feed_entry.description)
         print 'link'
         print self.link
         print 'description:'
         print safe_unicode(feed_entry.description)
     except:
         pass
     self.date_published = datetime.datetime.fromtimestamp(
         mktime(feed_entry.date_parsed))
     try:
         self.date_updated = datetime.datetime.fromtimestamp(
             mktime(feed_entry.updated_parsed))
     except:
         self.date_updated = self.date_published