view FeedUpdater.py @ 8:2da2b691345d

unfinished pretty printer for feed's plain text representation
author Dirk Olmes <dirk@xanthippe.ping.de>
date Tue, 27 Apr 2010 03:42:08 +0200
parents 215c34f61e95
children fd4c8bfa62d6
line wrap: on
line source


from datetime import datetime
from Feed import Feed
from FeedEntry import FeedEntry
import feedparser

def updateAllFeeds(session):
    allFeeds = session.query(Feed)
    for feed in allFeeds:
        FeedUpdater(session, feed).update()
        session.commit()

class FeedUpdater(object):
    def __init__(self, session, feed):
        self.session = session
        self.feed = feed
        
    def update(self):
        result = feedparser.parse(self.feed.rss_url)
        for entry in result.entries:
            self.processEntry(entry)

    def processEntry(self, entry):
        feedEntry = FeedEntry.findById(entry.id, self.session)
        if feedEntry is None:
            self.createFeedEntry(entry)
            
    def createFeedEntry(self, entry):
        new = FeedEntry()
        new.id = entry.id
        new.link = entry.link
        new.title = entry.title
        new.updated = datetime(*entry.updated_parsed[:6])
        new.summary = entry.summary
        new.feed = self.feed
        self.session.add(new)