2017-09-12 21:50:05 +02:00
|
|
|
# -*- 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
|
|
|
|
|
2018-03-04 22:55:37 +01:00
|
|
|
|
2017-09-12 16:50:26 +02:00
|
|
|
class GeoEntryExtension(BaseEntryExtension):
|
2017-09-12 21:50:05 +02:00
|
|
|
'''FeedEntry extension for Simple GeoRSS.
|
|
|
|
'''
|
|
|
|
|
2017-09-12 16:50:26 +02:00
|
|
|
def __init__(self):
|
2017-09-12 21:50:05 +02:00
|
|
|
# Simple GeoRSS tag
|
2017-09-12 16:50:26 +02:00
|
|
|
self.__point = None
|
|
|
|
|
2017-09-12 21:50:05 +02:00
|
|
|
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
|
|
|
|
|
2017-09-12 21:50:05 +02:00
|
|
|
def extend_rss(self, entry):
|
|
|
|
return self.extend_file(entry)
|
|
|
|
|
2017-09-12 16:50:26 +02:00
|
|
|
def extend_atom(self, entry):
|
2017-09-12 21:50:05 +02:00
|
|
|
return self.extend_file(entry)
|
2017-09-12 16:50:26 +02:00
|
|
|
|
|
|
|
def point(self, point=None):
|
2017-09-12 21:50:05 +02:00
|
|
|
'''Get or set the georss:point of the entry.
|
|
|
|
|
|
|
|
:param point: The GeoRSS formatted point (i.e. "42.36 -71.05")
|
2018-03-04 22:55:37 +01:00
|
|
|
:returns: The current georss:point of the entry.
|
2017-09-12 21:50:05 +02:00
|
|
|
'''
|
|
|
|
|
|
|
|
if point is not None:
|
|
|
|
self.__point = point
|
|
|
|
|
2017-09-12 16:50:26 +02:00
|
|
|
return self.__point
|