python-feedgen/feedgen/ext/geo_entry.py

56 lines
1.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
'''
feedgen.ext.geo_entry
~~~~~~~~~~~~~~~~~~~
Extends the FeedGenerator to produce Simple GeoRSS feeds.
:copyright: 2017, Bob Breznak <bob.breznak@gmail.com>
:license: FreeBSD and LGPL, see license.* for more details.
'''
2017-09-12 16:50:26 +02:00
from lxml import etree
from feedgen.ext.base import BaseEntryExtension
2017-09-12 16:50:26 +02:00
class GeoEntryExtension(BaseEntryExtension):
'''FeedEntry extension for Simple GeoRSS.
'''
2017-09-12 16:50:26 +02:00
def __init__(self):
# Simple GeoRSS tag
2017-09-12 16:50:26 +02:00
self.__point = None
def extend_file(self, entry):
'''Add additional fields to an RSS item.
:param feed: The RSS item XML element to use.
'''
2017-09-12 16:50:26 +02:00
GEO_NS = 'http://www.georss.org/georss'
if self.__point:
point = etree.SubElement(entry, '{%s}point' % GEO_NS)
point.text = self.__point
return entry
def extend_rss(self, entry):
return self.extend_file(entry)
2017-09-12 16:50:26 +02:00
def extend_atom(self, entry):
return self.extend_file(entry)
2017-09-12 16:50:26 +02:00
def point(self, point=None):
'''Get or set the georss:point of the entry.
:param point: The GeoRSS formatted point (i.e. "42.36 -71.05")
:returns: The current georss:point of the entry.
'''
if point is not None:
self.__point = point
2017-09-12 16:50:26 +02:00
return self.__point