""" Simple rss to html converter """
__version__ = "0.0.1"
__author__ = "Ricky L Wilson"
from feedparser import parse as parsefeed
import StringIO
def entry2html(**kwargs):
""" Format feedparser entry """
title = kwargs['title'].encode('utf-8')
link = kwargs['link'].encode('utf-8')
description = kwargs['description'].encode('utf-8')
template = """
<h2 class='title'>{title}</h2>
<a class='link' href='{link}'>{title}</a>
<span class='description'>{description}</span>
"""
return template.format(title=title, link=link, description=description)
def convert_feed(**kwargs):
""" Main loop """
out = StringIO.StringIO("")
for entry in parsefeed(kwargs['url']).entries:
title = entry['title']
link = entry['link']
description = entry['description']
print >>out, entry2html(title=title, link=link,
description=description)
return out.getvalue()
print convert_feed(url='http://stackoverflow.com/feeds')
Code Review