This module provides a class called AtomFeed which can beused to generate feeds in the Atom syndication format (see RFC 4287 [http://tools.ietf.org/html/rfc4287.html]).
Example:
def atom_feed(request):
feed = AtomFeed("My Blog", feed_url=request.url,
url=request.host_url,
subtitle="My example blog for a feed test.")
for post in Post.query.limit(10).all():
feed.add(post.title, post.body, content_type="html",
author=post.author, url=post.url, id=post.uid,
updated=post.last_update, published=post.pub_date)
return feed.get_response()
class werkzeug.contrib.atom.AtomFeed(title=None, entries=None, **kwargs)
A helper class that creates Atom feeds.
参数: | title – the title of the feed. Required. title_type – the type attribute for the title element. One of"html", "text" or "xhtml". url – the url for the feed (not the url of the feed) id – a globally unique id for the feed. Must be an URI. Ifnot present thefeed_urlis used, but one of both isrequired. updated – the time the feed was modified the last time. Mustbe a datetime.datetime [http://docs.python.org/dev/library/datetime.html#datetime.datetime] object. If notpresent the latest entry"supdatedis used. feed_url – the URL to the feed. Should be the URL that wasrequested. author – the author of the feed. Must be either a string (thename) or a dict with name (required) and uri oremail (both optional). Can be a list of (may bemixed, too) strings and dicts, too, if there aremultiple authors. Required if not every entry has anauthor element. icon – an icon for the feed. logo – a logo for the feed. rights – copyright information for the feed. rights_type – the type attribute for the rights element. One of"html", "text" or "xhtml". Default is"text". subtitle – a short description of the feed. subtitle_type – the type attribute for the subtitle element.One of "text", "html", "text"or "xhtml". Default is "text". links – additional links. Must be a list of dictionaries withhref (required) and rel, type, hreflang, title, length(all optional) generator – the software that generated this feed. This must bea tuple in the form (name, url, version). Ifyou don"t want to specify one of them, set the itemtoNone. entries – a list with the entries for the feed. Entries can alsobe added later with add().
|
---|
For more information on the elements seehttp://www.atomenabled.org/developers/syndication/
Everywhere where a list is demanded, any iterable can be used.
add(args, kwargs*)
Add a new entry to the feed. This function can either be calledwith a FeedEntry or some keyword and positional argumentsthat are forwarded to the FeedEntry constructor.
generate()
Return a generator that yields pieces of XML.
get_response()
Return a response object for the feed.
to_string()
Convert the feed into a string.
class werkzeug.contrib.atom.FeedEntry(title=None, content=None, feed_url=None, **kwargs)
Represents a single entry in a feed.
参数: | title – the title of the entry. Required. title_type – the type attribute for the title element. One of"html", "text" or "xhtml". content – the content of the entry. content_type – the type attribute for the content element. Oneof "html", "text" or "xhtml". summary – a summary of the entry"s content. summary_type – the type attribute for the summary element. Oneof "html", "text" or "xhtml". url – the url for the entry. id – a globally unique id for the entry. Must be an URI. Ifnot present the URL is used, but one of both is required. updated – the time the entry was modified the last time. Mustbe a datetime.datetime [http://docs.python.org/dev/library/datetime.html#datetime.datetime] object. Required. author – the author of the entry. Must be either a string (thename) or a dict with name (required) and uri oremail (both optional). Can be a list of (may bemixed, too) strings and dicts, too, if there aremultiple authors. Required if the feed does not have anauthor element. published – the time the entry was initially published. Mustbe a datetime.datetime [http://docs.python.org/dev/library/datetime.html#datetime.datetime] object. rights – copyright information for the entry. rights_type – the type attribute for the rights element. One of"html", "text" or "xhtml". Default is"text". links – additional links. Must be a list of dictionaries withhref (required) and rel, type, hreflang, title, length(all optional) categories – categories for the entry. Must be a list of dictionarieswith term (required), scheme and label (all optional) xml_base – The xml base (url) for this feed item. If not providedit will default to the item url.
|
---|
For more information on the elements seehttp://www.atomenabled.org/developers/syndication/
Everywhere where a list is demanded, any iterable can be used.