Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tips on creating RSS/XML easily in python

Tags:

python

xml

rss

I have a list if these 3 items: title and link and a html based description and I am looking for a library or external tool which can be fed these 3 items and create a rss xml page. Does such a thing exist?

like image 532
Recursion Avatar asked Jan 20 '10 07:01

Recursion


1 Answers

I suggest you use a template and feed the list of items to the template.

Example Jinja2 template (Atom, not RSS, but you get the idea), assuming that the items are 3-tuples (title, link, html):

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <author>Author's name</author>
    <title>Feed title</title>
    {%for item in items %}
    <entry>
        <title>{{item[0]}}</title>
        <link href="{{item[1]}}"/>
        <content type="html">{{item[2]}}</content>
    </entry>
    {%endfor%}
</feed>

Code to feed content to the template and output the result:

import jinja2
env = jinja2.Environment(loader=jinja2.FileSystemLoader("."))
print env.get_template("feedtemplate.xml").render(items=get_list_of_items())
like image 195
codeape Avatar answered Oct 05 '22 12:10

codeape