view feedupdate-main.py @ 10:01a86b178e60

catch the FeedUpdateException that might be raised when updating a feed, print it and continue with next feed
author Dirk Olmes <dirk@xanthippe.ping.de>
date Tue, 27 Apr 2010 20:08:21 +0200
parents 87317ba41816
children e87c54b3a216
line wrap: on
line source

#!/usr/bin/env python

from ConfigParser import ConfigParser
from Feed import Feed
from FeedUpdater import updateAllFeeds
import Mapping
import socket
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

def loadDatabaseProperties():
    hostname = socket.gethostname()
    filename = "database-%s.ini" % hostname

    parser = ConfigParser();
    parser.read(filename)
    return parser.get("database", "url")

def createFeed(session):
    if len(session.query(Feed).all()) == 0:
        newFeed = Feed("Joel on Software", "http://www.joelonsoftware.com/rss.xml")
        session.add(newFeed)
        session.commit()

def listFeeds(session):
    allFeeds = session.query(Feed)
    for feed in allFeeds:
        print "\n\nfeed: " + feed.name
        for entry in feed.entries:
            print entry.title

if __name__ == "__main__":
    databaseUrl = loadDatabaseProperties()
    engine = create_engine(databaseUrl,echo=True)
    Mapping.createMapping(engine)
    SessionMaker = sessionmaker(bind = engine)
    session = SessionMaker()
    
    createFeed(session)
    updateAllFeeds(session)
    #listFeeds(session)