6.14. RSS stream generator
6.14.1 RSS()
Karrigell provides a class,RSS(), allowing programmer to easily generate RSS 2.0 streams.RSS() use is :
from k_rss import RSS
rss = RSS(parameters)
RSS() parameters are named arguments in the following list :
title(mandatory)link(mandatory)description(mandatory)languagecopyrightmanagingEditorwebMasterpubDatelastBuildDatecategorygeneratordocscloudttlimageratingskipHoursskipDays
6.14.2 AddItem()
Once, the Channel is created withRSS(), you can add items with AddItem() method.AddItem() use is :
rss.AddItem(parameters)
AddItem() parameters are named arguments in the following list :
titlelinkdescriptionauthorcategorycommentsenclosureguidpubDatesource
title or description has to be specified in AddItem() parameters.
6.14.3 Parameters type
Parameters ofRSS() and AddItem() can be of the following type :
- text : a string or a unicode string
- date : datetime.datetime converted to text with the correct formatting. Timezone is managed (see note).
- image : a dictionnary with the following keys :
- url (mandatory)
- title (mandatory)
- link (mandatory)
- width
- height
- description
6.14.4 Render() and RenderInFile()
To generate the stream, you can useRender() or RenderInFile().
Render() accepts a single parameter : the output encoding (optional).
When not specified, default output encoding is iso-8859-1.
Render() outputs a unicode string correctly formatted.
RenderInfile() accepts two parameters : a filename and the output encoding (optional).
RenderInfile() works like Render() but generates a file and returns nothing.
6.14.5 Example
from k_rss import RSS
import datetime
rss = RSS(title="Karrigell",
description="Flexible Python web framework, with a clear and intuitive syntax.",
link="http://www.karrigell.com",
webMaster="quentel.pierre@wanadoo.fr (Pierre Quentel)",
language="en",
generator="Karrigell RSS generator",
image={"url":"http://karrigell.sourceforge.net/images/karrigell_skeudenn.png",
"title":"Karrigell",
"link":"http://www.karrigell.com"}
)
rss.AddItem (title='Last item',
description='My most recent item.',
pubDate = datetime.datetime.now())
rss.AddItem (title='First item',
description='My first item.',
pubDate = datetime.datetime(year=2009, month=3, day=16, hour=22, minute=34, second=17))
print rss.Render()
In this example, an RSS stream is generated with "Karrigell" as a title. Two items are added.