This is a port of Django’s feeed generator for creating RSS and Atom feeds. The Geo classes for publishing geographical (GIS) data are also ported.
Syndication feed generation library – used for generating RSS, etc.
>>> import webhelpers.feedgenerator as feedgenerator >>> feed = feedgenerator.Rss201rev2Feed( ... title=u"Poynter E-Media Tidbits", ... link=u"http://www.poynter.org/column.asp?id=31", ... description=u"A group weblog by the sharpest minds in online media/journalism/publishing.", ... language=u"en", ... ) >>> feed.add_item(title="Hello", link=u"http://www.holovaty.com/test/", description="Testing.") >>> fp = open('test.rss', 'w') >>> feed.write(fp, 'utf-8') >>> fp.close()
For definitions of the different versions of RSS, see: http://diveintomark.org/archives/2004/02/04/incompatible-rss
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
DefaultFeed is an alias for Rss201rev2Feed.
Creates a TagURI. See http://diveintomark.org/archives/2004/05/28/howto-atom-id
These classes allow you to include geometries (e.g., latitude/longitude) in your feed. The implementation is in a mixin class:
This mixin provides the necessary routines for SyndicationFeed subclasses to produce simple GeoRSS or W3C Geo elements.
Subclasses recognize a geometry keyword argument to .add_item(). The value may be any of several types:
The mixin provides one class attribute:
The default value False indicates that input data is in latitude/longitude order. Change to True if the input data is longitude/latitude. The output is always written latitude/longitude to conform to the GeoRSS spec.
The reason for this attribute is that the Django original stores data in longitude/latutude order and reverses the arguments before writing. WebHelpers does not do this by default, but if you’re using Django data or other data that has longitude first, you’ll have to set this.
This routine adds a GeoRSS XML element using the given item and handler.
Adds a GeoRSS point with the given coords using the given handler. Handles the differences between simple GeoRSS and the more popular W3C Geo specification.
In GeoRSS coordinate pairs are ordered by lat/lon and separated by a single white space. Given a tuple of coordinates, this will return a unicode GeoRSS representation.
Two concrete subclasses are provided:
A minimal geometry class is included:
A basic geometry class for GeoFeedMixin.
Instances have two public attributes:
“point”, “linestring”, “linearring”, “polygon”
For point, a tuple or list of two floats: (X, Y).
For linestring or linearring, a string: "X0 Y0 X1 Y1 ...".
For polygon, a list of strings: ["X0 Y0 X1 Y1 ..."]. Only the first element is used because the Geo classes support only the exterior ring.
The constructor does not check its argument types.
This class was created for WebHelpers based on the interface expected by GeoFeedMixin.add_georss_element(). The class is untested. Please send us feedback on whether it works for you.