forked from lkiesow/python-feedgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better format Geo and GeoEntry. Add test for Geo Extension
- Loading branch information
Showing
3 changed files
with
72 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
from lxml import etree | ||
# -*- coding: utf-8 -*- | ||
''' | ||
feedgen.ext.geo | ||
~~~~~~~~~~~~~~~~~~~ | ||
Extends the FeedGenerator to produce Simple GeoRSS feeds. | ||
:copyright: 2017, Bob Breznak <[email protected]> | ||
:license: FreeBSD and LGPL, see license.* for more details. | ||
''' | ||
|
||
from feedgen.ext.base import BaseExtension | ||
|
||
class GeoExtension(BaseExtension): | ||
def __init__(self): | ||
self.__point__ = None | ||
'''FeedGenerator extension for Simple GeoRSS. | ||
''' | ||
|
||
def extend_ns(self): | ||
return { 'georss' : 'http://www.georss.org/georss' } | ||
|
||
def extend_rss(self, rss_feed): | ||
return rss_feed | ||
|
||
def extend_atom(self, atom_feed): | ||
return atom_feed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
''' | ||
feedgen.ext.geo_entry | ||
~~~~~~~~~~~~~~~~~~~ | ||
Extends the FeedGenerator to produce Simple GeoRSS feeds. | ||
:copyright: 2017, Bob Breznak <[email protected]> | ||
:license: FreeBSD and LGPL, see license.* for more details. | ||
''' | ||
|
||
from lxml import etree | ||
from feedgen.ext.base import BaseEntryExtension | ||
|
||
class GeoEntryExtension(BaseEntryExtension): | ||
'''FeedEntry extension for Simple GeoRSS. | ||
''' | ||
|
||
def __init__(self): | ||
# Simple GeoRSS tag | ||
self.__point = None | ||
|
||
def extend_rss(self, entry): | ||
def extend_file(self, entry): | ||
'''Add additional fields to an RSS item. | ||
:param feed: The RSS item XML element to use. | ||
''' | ||
|
||
GEO_NS = 'http://www.georss.org/georss' | ||
|
||
if self.__point: | ||
|
@@ -14,9 +35,20 @@ def extend_rss(self, entry): | |
|
||
return entry | ||
|
||
def extend_rss(self, entry): | ||
return self.extend_file(entry) | ||
|
||
def extend_atom(self, entry): | ||
return self.extend_rss(self, entry) | ||
return self.extend_file(entry) | ||
|
||
def point(self, point=None): | ||
self.__point = point or '0.0 0.0' | ||
'''Get or set the georss:point of the entry. | ||
:param point: The GeoRSS formatted point (i.e. "42.36 -71.05") | ||
:returns: The author of the podcast. | ||
''' | ||
|
||
if point is not None: | ||
self.__point = point | ||
|
||
return self.__point |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters