The feed generator is intended for use in controllers, and generates an output stream. Currently the following feeds can be created by imported the appropriate class:
All of these format specific Feed generators inherit from the SyndicationFeed() class.
Example controller method:
import logging
from pylons import request, response, session
from pylons import tmpl_context as c
from pylons.controllers.util import abort, redirect_to, url_for
from webhelpers.feedgenerator import Atom1Feed
from helloworld.lib.base import BaseController, render
log = logging.getLogger(__name__)
class CommentsController(BaseController):
def index(self):
feed = Atom1Feed(
title=u"An excellent Sample Feed",
link=url_for(),
description=u"A sample feed, showing how to make and add entries",
language=u"en",
)
feed.add_item(title="Sample post",
link=u"http://hellosite.com/posts/sample",
description="Testing.")
response.content_type = 'application/atom+xml'
return feed.writeString('utf-8')
Base class for all syndication feeds. Subclasses should provide write()
Adds an item to the feed. All args are expected to be Python Unicode objects except pubdate, which is a datetime.datetime object, and enclosure, which is an instance of the Enclosure class.
Add elements on each item (i.e. item/entry) element.
Add elements in the root (i.e. feed/channel) element. Called from write().
Return extra attributes to place on each item (i.e. item/entry) element.
Returns the latest item’s pubdate. If none of them have a pubdate, this returns the current date/time.
Return extra attributes to place on the root (i.e. feed/channel) element. Called from write().
Outputs the feed in the given encoding to outfile, which is a file-like object. Subclasses should override this.
Returns the feed in the given encoding as a string.
Represents an RSS enclosure
Creates a TagURI. See http://diveintomark.org/archives/2004/05/28/howto-atom-id