feed2html.py feed-to-HTML converter in Python
About
feed2html.py is an open source/free source command line tool that takes a RSS/RDF/Atom news feed, and converts it into HTML documents (or other text documents using templates). It is developed in Python (2.3+ required), and it requires the universal feed parser to be installed separately. It can take input from an URL, a local file or from standard input, and can write the output to a local file or standard output. It has a built in template engine to allow customisation of the resulting HTML. feed2html.py can also be invoked from the web server as a CGI application.
feed2html.py should run whereever Python does. It is released as a free software using Python Software Foundation License.
Download feed2html.py
Usage
Command Line
Using feed2html.py from the command line:
% feed2html.py -h
Usage:
feed2html.py [options]
Options:
-D var=val Define variable equals to value.
-h Display this help message.
-i input Feed input. It can be an URL, a local file name, or '-' for
standard input. (Default standard input)
-o output HTML output. It can be a local file name, or '-' for standard
output. (Default standard output)
-t tplfile Template file name. If omitted, default template will be used.
For example, downloading the latest news for nerds from Slashdot:
% feed2html.py -i http://slashdot.org/index.rss > slashdot.html
CGI
Using feed2html.py as CGI application:
- Place
feed2html.pyinto yourcgi-bindirectory. - Point your browser at it, i.e. http://<your site>/cgi-bin/feed2html.py?i=<input>&t=<tplfile>
Note that:
- “input” parameter is always required, and it should always be an URL.
- “tplfile” parameter is optional, and default template will be used if not present. Template file must be inside the same directory or in the sub-directories as the
feed2html.py.
Template
Default Template
" />
Template Tags
There are two types of tags – control tags and value tags. Control tags let you iterate through a list, or allows conditional execution of a template segment. Value tags injects value in the place where the tag is. These tags closely follow what feedparser provides.
- <tpl:entries> … </tpl:entries>
- Iterate through all entries.
- <tpl:contents> … </tpl:contents>
- Iterate through full content of the current entry.
- <tpl:contributors> … </tpl:contributors>
- Iterate through the contributors of the current entry.
- <tpl:enclosures> … </tpl:enclosures>
- Iterate through the enclosures of the current entry.
- <tpl:feed value=”…”/>
- Print a value related to the feed.
- <tpl:entry value=”…”/>
- Print a value related to the current feed.
- <tpl:content value=”…”/>
- Print a value related to the currently selected current of the current entry.
- <tpl:contributor value=”…”/>
- Print a value related to the currently selected contributor of the current entry.
- <tpl:enclosure value=”…”/>
- Print a value related to the currently selected enclosure of the current entry.
XXX: template section to be written.
History
- 1.0 – 2 May 2005
- Initial implementation. Code ripped off from Bloglines2HTML.
Links to This Article
Comments
Can you give a sample of the syntax for this tag:
…
I want to process an entry when a tag (call it john) has a certain value say “foo”
Is this syntax correct:
…
Thanks!
Add a comment
Gravatar is used. Email address is required but will not be displayed. Please keep your comment on topic. No spamming and/or bad language. First time poster will be moderated. Scott reserves the right to delete/edit your comments.

Hi,
I started to use your feed2html.py code to process some feeds for my website.
I’ve had a lot of success but I’m having trouble figuring out the syntax of the
template command (from the source code)
…
The XML entry I want to test for is called “contact”
so I am using
Contact email:
to selectively lay in the words “Contact email:”
However, it seems to just ignore the tags.
Any idea what I’m doing wrong?
Thanks again in advance,
John