rsslib

Create RSS feeds in Python. Open source.

You may freely use this code in any way you can think of.

download ·  contact
%python
Python 2.3.3 (#1, Apr 13 2004, 07:09:05) 
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits" or "license" for more information.
>>> import rsslib
>>> rss = rsslib.RSS()
>>> rss.channel.link = "http://channel.com"
>>> rss.channel.title = "my channel title"
>>> rss.channel.description = "my channel description"
>>> item = rsslib.Item()
>>> item.link = "http://link.com"
>>> item.description = "my description"
>>> item.title = "item title"
>>> rss.addItem( item )
>>> print rss.write()
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" >
<channel>
<title>my channel title</title>
<link>http://channel.com</link>
<description>my channel description</description>

<item><title>item title</title>
<link>http://link.com</link>
<description>my description</description>
</item>

</channel>
</rss>

>>> help(rsslib)

Help on module rsslib:

NAME
    rsslib - RSS 2.0 Generator

DESCRIPTION
    This library encapsulates the generation of an RSS (2.0) feed

CLASSES
    Channel
    Item
    Namespace
    RSS
    
    class RSS
     |  RSS
     |  
     |  This class encapsulates the creation of an RSS 2.0 feed
     |  
     |  The RSS2.0 spec can be found here: 
     |  http://blogs.law.harvard.edu/tech/rss
     |  
     |  
     |  RSS validator :  http://rss.scripting.com
     |  
     |  
     |  The generation of an RSS feed is simple, the following is a
     |  sample:
     |      from rsslib import RSS, Item, Namespace
     |      rss = RSS()
     |      rss.channel.link = "http://channel.com"
     |      rss.channel.title = "my channel title"
     |      rss.channel.description = "my channel description"
     |
     |      ns = Namespace( "foobar", "http://foobar.baz" )
     |      rss.addNamespace( ns )
     |
     |      item = Item()
     |      item.link = "http://link.com"
     |      item.description = "my link description"
     |      item.title ="my item title"
     |      item.nsItems[ns.name + ":foo"] = "bar"
     |      rss.addItem( item )
     |
     |      item = Item()
     |      item.link = "http://link2.com"
     |      item.description = "my link2 description"
     |      item.title ="my item2 title"
     |      item.nsItems[ns.name +":foo"] = "foo bar baz"
     |      rss.addItem( item )
     |
     |      print rss.write()
     |
     |  output:
     |      <?xml version="1.0" encoding="UTF-8"?>
     |      <rss version="2.0" xmlns:foobar="http://foobar.baz" >
     |      <channel>
     |      <title>my channel title</title>
     |      <link>http://channel.com</link>
     |      <description>my channel description</description>
     |
     |      <item><title>my item title</title>
     |      <link>http://link.com</link>
     |      <description>my link description</description>
     |      <foobar:foo>bar</foobar:foo>
     |      </item>
     |
     |      <item><title>my item2 title</title>
     |      <link>http://link2.com</link>
     |      <description>my link2 description</description>
     |      <foobar:foo>foo bar baz</foobar:foo>
     |      </item>
     |
     |      </channel>
     |      </rss>
     |
     |     
     |  author: cmallory /a t/ berserk /dot/ o r g
     |
     |  Methods defined here:
     |  
     |  __init__(self)
     |  
     |  generateChannel(self)
     |  
     |  generateItems(self)
     |  
     |  optionalWrite(self, key, val)
     |  
     |  write(self)
     
    class Channel
     |  Channel
     |  
     |      (http://blogs.law.harvard.edu/tech/rss)
     |       
     |      This object represents an RSS channel (as of ver2.0)
     |  
     |  Methods defined here:
     |  
     |  __init__(self)
     |  
     |  initialized(self)
    
    class Item
     |  Item
     |   
     |  http://blogs.law.harvard.edu/tech/rss#hrelementsOfLtitemgt
     |   
     |  A channel may contain any number of <item>s. An item may 
     |  represent a "story" -- much like a story in a newspaper or magazine; 
     |  if so its description is a synopsis of the story, and the link 
     |  points to the full story. An item may also be complete in itself, 
     |  if so, the description contains the text (entity-encoded HTML is 
     |  allowed; see examples), and the link and title may be omitted. 
     |  All elements of an item are optional, however at least one of 
     |  title or description must be present.
     |  
     |  Methods defined here:
     |  
     |  __init__(self)
    
    class Namespace
     |  Methods defined here:
     |  
     |  __init__(self, name, url)
     
>>>
%