Universal Feed Formatter 0.1
The Universal Feed Formatter (or just "feedformatter") is a simple Python module for transforming a dictionary-based structure of feed and item information into a number of valid feed formats. Currently supported formats are RSS 1.0, RSS 2.0 and Atom 1.0. You can think of it as the opposite of the well known and excellent Universal Feed Parser (in terms of what it does, not of how high quality it is - yet!).
feedformatter is in an "alpha" state - it does not currently support all of the features for each of the formats it can produce output for. It has undergone minimal testing and there is room for substantial code clean up. It has been released in this form in line with the "release early, release often" philosophy of free software development. This said, I do use it to generate the feeds for this website, and the feeds it generates do survive the relevant W3C feed validators. In short: it's not fantastic, but it's not absolutely terrible either.
Requirements
feedformatter uses ElementTree library to produce valid XML output. The ElementTree library is part of the Python standard library as of Python 2.5. However, ElementTree can be downloaded separately for earlier earlier versions. Supposedly it will work with any version after 1.5.2, which should cover any Python installation you can find today.
License
feedformatter is distributed under a standard 3-clause BSD license. It's as free as software gets.
Download
Download the latest version of feedformatter, feedformatter 0.1, which was released on March 2, 2008.
Complete Instructions
The feedparser module contains just one class definition that you need to worry
about in typical usage - the Feed
class. A Feed object represents, funnily
enough, a complete feed. It has two attributes, both dictionaries. The
feed
dictionary attribute contains values specific to the feed overall. It
may contain values for the following keys:
title
- The title of the feeddesc
- A description of the feedlink
- A URL for either the feed itself or the relevant website's homepageauthor
- The name of the author of the items in the feedpublished
- The date and time at which the feed was last updated. This may be in the form of seconds since the Unix Epoch (as a float or a string representation of float) or as a 9-part time tuple.
The items
dictionary attribute should contain a list of dictionaries. Each
dictionary in this list contains values specific to one single item in the
feed. Each item dictionary may contain values for the following keys:
title
- The title of the feed itemdesc
- A description of the feed itemurl
- A URL for the page or file the feed item is aboutpubDate
- The date and time at which this item was added to the feed, in one of the same formats as the ''published'' attribute of the ''feed'' dictionary.
The feed
and items
dictionaries should be passed in as the only two
arguments to the Feed class' constructor to get a populated Feed object. For
now, you can't instantiate an empty object and then assign things using
methods. I'm sure this will turn up in a later release.
There is also a factory function named fromUFP
. The goal of this function is
to take as input a dictionary which is the output of the excellent Universal
Feed Parser and return a properly populated Feed object. At the moment, it
just throws a NotImplementedError
exception. It's only in there to show that
I thought of it first. :p
Once a Feed object has been populated, you may call any of the following methods:
render_rss1(filename)
render_rss2(filename)
render_atom(filename)
These methods do just what you would expect them to do - write the feed
information to a file with the given filename in the appropriate format. Any
one of these methods may raise an InvalidFeed exception if the Feed object has
not been populated with sufficient information to produce valid output in the
format requested. For example, the Atom format specification states that there
must be either at least one "author" element within the "feed" element OR at
least one "author" element within each "entry" element. If your input
dictionaries do not have the relevant keys to make this happen, the
render_atom
method will complain appropriately.
Contribute
Bug reports and suggestion for improvement of feedformatter are very welcome: just email them to me. Full credit will be given on this page for bug reports, fixes, etc. Feel free to email me even just to let me know you think feedformatter is neat, too.