Simple RSS to HTML converter Is this code pythonic, easy to read, stable, or missing something?

# -*- coding: utf-8 -*-
""" Simple rss to html converter """

__version__ = "0.0.1"
__author__ = "Ricky L Wilson"

import StringIO
from feedparser import parse as parsefeed
from bs4 import BeautifulSoup as bs
from unicodedata import normalize


def flatten_unicode_keys(dic):
    '''pass unicode keywords to **kwargs '''
    for key in dic.keys():
        if isinstance(key, unicode):
            value = dic[key]
            del dic[key]
            dic[normalize('NFKD',key).encode('ascii','ignore')] = value


def entry2html(**kwargs):
    """ Format feedparser entry """
    flatten_unicode_keys(kwargs)
    title = kwargs['title']
    link = kwargs['link']
    description = kwargs['description']
    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;{description}&lt;/span&gt;
    """
    return template.format(title=title, link=link, description=description).encode('utf-8')


def convert_feed(**kwargs):
    """ Main loop """
    flatten_unicode_keys(kwargs)
    out = StringIO.StringIO("")
    for entry in parsefeed(kwargs['url']).entries:
        title = entry['title']
        link = entry['link']
        description = entry['description']
        print &gt;&gt; out, entry2html(title=title, link=link, description=description)
    return bs(out.getvalue(), 'lxml').prettify()


def save_file(url, fname):
    ''' Save data to disc'''
    with open(fname, 'w') as file_object:
        file_object.write(convert_feed(url=url).encode('utf-8'))

save_file('http://stackoverflow.com/feeds', 'index.html')
The small improvement I would like to suggest you is related to performance in terms of speed.

In flatten_unicode_keys(dic), you use for key in dic.keys(): which is less fast than for key in dic:. This is mentioned in PEP 234:


  
  Dictionaries implement a tp_iter slot that returns an efficient
  iterator that iterates over the keys of the dictionary. [...] This 
  means that we can write

for k in dict: ...

  
  which is equivalent to, but much faster than

for k in dict.keys(): ...

  


An other side note: it is a better coding habit not to encode the container type into the name. So instead, for example, of typing dic, use a name which actually better describes what that dictionary consists of.