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)
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)
-
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)
- 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.
-
latest_post_date()
Returns the latest item’s pubdate.
If none of them have a pubdate, this returns the current date/time.
-
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.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)
-
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)
-
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