the further adventures of

Mike Pirnat

a leaf on the wind

« Previous Post Next Post »

Fun With RSS and Python

I should have looked into this stuff a while ago, because it's entirely too handy and, in a word, pythonic. I will probably rewrite my crufty home-brew LiveJournal RSS parser using Mark Pilgrim's excellent Universal Feed Parser. Additionally, since I'm not sure if Planet allows easy filtering based on category, and I might like my occasional TurboGears rambling to show up there, I think I will combine feedparser with PyRSS2Gen to build a simple little program to pull, filter, and re-emit RSS feeds.

Of course, knowing my luck, something like that already exists, but at least it'll be fun. ;-)

Basically, it would be something like this:

import feedparser
import datetime
import PyRSS2Gen

# get the data
d = feedparser.parse('')

# do the filtering & build a list of RSSItem objects
items = [PyRSS2Gen.RSSItem(
    title = x.title,
    link =,
    description = x.summary,
    guid =,
    pubDate = datetime.datetime(
    for x in d.entries if some_criteria(x)]

# make the RSS2 object
rss = PyRSS2Gen.RSS2(
    title = d.feed.title,
    link =,
    description = "ExileJedi's Filtered RSS Feed",
    lastBuildDate =,
    items = items)

#emit the feed
xml = rss.to_xml() # or perhaps do rss.write_xml(some_file)

blog comments powered by Disqus

« Previous Post Next Post »