How to Generate an RSS feed from a Database query
Generating an RSS feed from a Database query is ridiculously easy with Python's awkwardly named PyRSS2Gen module.Here's how simple it is. Create your database query, and then throw it into PyRSS2Gen's RSSItem method. Then create an RSS2 feed. This code shows you how:
items = []
for row in databaseitems:
items.append(
PyRSS2Gen.RSSItem(
title = row['title'], link = row['link'],
description = row['description'],
guid = PyRSS2Gen.Guid(row['guid']), pubDate = row['pub_date'] ) )
PyRSS2Gen.RSS2(
title = "Feed Title",
link = "http://localhost/test URL",
description = "Feed Description",
lastBuildDate = datetime.datetime.now(),
items = items).write_xml(open("test.xml", "w"))
You can then connect to this with your rss reader by publishing the xml to a web directory and pointing your RSS reader to the location of the XML file. Very nice.
