feedgenerator – Feed generator

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:

  • RssFeed
  • RssUserland091Feed
  • Rss201rev2Feed
  • Atom1Feed

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')

Module Contents

class webhelpers.feedgenerator.SyndicationFeed(title, link, description, language=None, author_email=None, author_name=None, author_link=None, subtitle=None, categories=None, feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs)

Base class for all syndication feeds. Subclasses should provide write()

__init__(title, link, description, language=None, author_email=None, author_name=None, author_link=None, subtitle=None, categories=None, feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs)
add_item(title, link, description, author_email=None, author_name=None, author_link=None, pubdate=None, comments=None, unique_id=None, enclosure=None, categories=(), item_copyright=None, ttl=None, **kwargs)

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_item_elements(handler, item)

Add elements on each item (i.e. item/entry) element.

add_root_elements(handler)

Add elements in the root (i.e. feed/channel) element. Called from write().

item_attributes(item)

Return extra attributes to place on each item (i.e. item/entry) element.

latest_post_date()

Returns the latest item’s pubdate. If none of them have a pubdate, this returns the current date/time.

root_attributes()

Return extra attributes to place on the root (i.e. feed/channel) element. Called from write().

write(outfile, encoding)

Outputs the feed in the given encoding to outfile, which is a file-like object. Subclasses should override this.

writeString(encoding)

Returns the feed in the given encoding as a string.

class webhelpers.feedgenerator.Enclosure(url, length, mime_type)

Represents an RSS enclosure

class webhelpers.feedgenerator.RssFeed(title, link, description, language=None, author_email=None, author_name=None, author_link=None, subtitle=None, categories=None, feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs)
class webhelpers.feedgenerator.RssUserland091Feed(title, link, description, language=None, author_email=None, author_name=None, author_link=None, subtitle=None, categories=None, feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs)
class webhelpers.feedgenerator.Rss201rev2Feed(title, link, description, language=None, author_email=None, author_name=None, author_link=None, subtitle=None, categories=None, feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs)
class webhelpers.feedgenerator.Atom1Feed(title, link, description, language=None, author_email=None, author_name=None, author_link=None, subtitle=None, categories=None, feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs)
webhelpers.feedgenerator.rfc2822_date(date)
webhelpers.feedgenerator.rfc3339_date(date)
webhelpers.feedgenerator.get_tag_uri(url, date)

Creates a TagURI. See http://diveintomark.org/archives/2004/05/28/howto-atom-id

Read the Docs v: v1.0.1rc1
Versions
latest
v1.0.1rc1
v0.9.7
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.