view RssAtomFeed.py @ 4:df9d4e704257

Made the architecture a little cleaner, but it's still pretty messy; I really need to turn some OO-like-hacks into actual OO constructions. At least the Config.py structure is simpler.
author Atul Varma <varmaa@toolness.com>
date Sat, 16 Feb 2008 21:56:15 -0600
parents
children
line wrap: on
line source

import Config
import urllib2

def getFeedInfo():
    for feed in Config.RSS_ATOM_FEEDS:
        yield dict( feed )

def _getHandlers():
    try:
        import LocalAuth
        handlers = LocalAuth.getAuthHandlers()
    except ImportError:
        print "No LocalAuth.py found, assuming no auth handlers."
        handlers = []
    return handlers

def update( feed ):
    # Yes, we need to rebuild the opener and the handlers every
    # time through this loop, or else things will fail on multiple
    # Livejournal requests.
    opener = urllib2.build_opener( *_getHandlers() )
    print "Fetching feed for %s..." % feed["name"]
    data = opener.open( feed["url"] )
    fileObj = open( feed["filename"], "w" )
    fileObj.write( data.read() )
    fileObj.close()