Atom Syndication

This module provides a class called AtomFeed which can beused to generate feeds in the Atom syndication format (see RFC 4287).

Example:

  1. def atom_feed(request):
  2. feed = AtomFeed("My Blog", feed_url=request.url,
  3. url=request.host_url,
  4. subtitle="My example blog for a feed test.")
  5. for post in Post.query.limit(10).all():
  6. feed.add(post.title, post.body, content_type='html',
  7. author=post.author, url=post.url, id=post.uid,
  8. updated=post.last_update, published=post.pub_date)
  9. 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 the feed_url is used, but one of both isrequired.
  • updated – the time the feed was modified the last time. Mustbe a datetime.datetime object. If notpresent the latest entry’s updated is 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 itemto None.
  • 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 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 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.