RSS to HTML script - version two I wrote this script that downloads an RSS feed and converts it to HTML. One of my only concerns is my variable naming because I suck at naming things.

# -*- coding: utf-8 -*-
"""Simple RSS to HTML converter."""

__version__ = "0.0.2"
__author__ = "Ricky L Wilson"

from bs4 import BeautifulSoup
from feedparser import parse as parse_feed


TEMPLATE = u"""
&lt;h2 class='title'&gt;{title}&lt;/h2&gt;
&lt;a class='link' href='{link}'&gt;{title}&lt;/a&gt;
&lt;span class='description'&gt;{summary}&lt;/span&gt;
"""

def entry_to_html(**kwargs):
    """Formats feedparser entry."""
    return TEMPLATE.format(**kwargs).encode('utf-8')


def convert_feed(url):
    """Main loop."""
    html_fragments = [entry_to_html(**entry) for entry in parse_feed(url).entries]
    return BeautifulSoup("\n".join(html_fragments), 'lxml').prettify()


def save_file(url, filename):
    """Saves data to disc."""
    with open(filename, 'w') as file_object:
        file_object.write(convert_feed(url).encode('utf-8'))


if __name__ == '__main__':
    save_file('http://stackoverflow.com/feeds', 'index.html')
    with open('index.html') as fobj:
        print fobj.read()
About the generated HTML

Each feed item should become an article. This would also allow you to include the generated HTML on any page without having to adjust the heading levels. Unless you know that h2 would always be the correct heading element in your case, you might want to use h1 instead.

You could give the a element the bookmark link type.

Unless you remove markup from the feed item’s description, you might want to use a div instead of a span, because a span can’t contain many elements that might appear in the description.

You could specify a class on the article element, and omit the classes on its child elements. Less potential to conflict with classes that might already be used in the document.

&lt;article class='feed-item'&gt;
  &lt;h1&gt;{title}&lt;/h1&gt;
  &lt;a href='{link}' rel='bookmark'&gt;{title}&lt;/a&gt;
  &lt;div&gt;{summary}&lt;/div&gt;
&lt;/article&gt;