summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-09-20 11:06:29 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-09-20 11:06:29 +0200
commit5117e854903c77c2e930e26e80d1eecb0a2951f0 (patch)
tree6de1c801d767a19e4072a2163ca5c0c3acabdc85
parent1c6d8fb4c6cce937c31f07629db3827ba7eaf575 (diff)
downloadChimère-5117e854903c77c2e930e26e80d1eecb0a2951f0.tar.bz2
Chimère-5117e854903c77c2e930e26e80d1eecb0a2951f0.zip
GeoRSS import: manage new version of feedparser
-rw-r--r--chimere/tests.py2
-rw-r--r--chimere/tests/georss_simple.xml8
-rw-r--r--chimere/utils.py37
-rw-r--r--requirements.txt2
4 files changed, 38 insertions, 11 deletions
diff --git a/chimere/tests.py b/chimere/tests.py
index adf806b..71fa12b 100644
--- a/chimere/tests.py
+++ b/chimere/tests.py
@@ -303,7 +303,7 @@ class GeoRSSImporterTest(TestCase, ImporterTest):
importer_type='RSS', source=test_dir_path + 'tests/eqs7day-M5.xml')
importer2.categories.add(subcategories[1])
- self.marker_importers = [(importer1, 1), (importer2, 32)]
+ self.marker_importers = [(importer1, 2), (importer2, 32)]
class HtmlXsltImporterTest(TestCase, ImporterTest):
diff --git a/chimere/tests/georss_simple.xml b/chimere/tests/georss_simple.xml
index 8697f16..4649492 100644
--- a/chimere/tests/georss_simple.xml
+++ b/chimere/tests/georss_simple.xml
@@ -18,4 +18,12 @@
<summary>We just had a big one.</summary>
<georss:point>45.256 -71.92</georss:point>
</entry>
+ <entry>
+ <title>M 4.2, Luna Way</title>
+ <link href="http://example.org/2006/10/10/atom02"/>
+ <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6b</id>
+ <updated>2006-08-17T07:02:32Z</updated>
+ <summary>We just had another big one.</summary>
+ <georss:line>45.256 -110.45 46.46 -109.48 43.84 -109.86</georss:line>
+ </entry>
</feed>
diff --git a/chimere/utils.py b/chimere/utils.py
index cc235d0..bd09b9e 100644
--- a/chimere/utils.py
+++ b/chimere/utils.py
@@ -674,14 +674,31 @@ class GeoRSSManager(ImportManager):
if feed['bozo'] and not isinstance(
feed['bozo_exception'], feedparser.CharacterEncodingOverride):
return (0, 0, _(u"RSS feed is not well formed"))
- for item in feed['items']:
- if "georss_point" not in item and 'georss_line' not in item \
+ # differ with feed parser version
+ item_key = 'items'
+ if 'entries' in feed:
+ item_key = 'entries'
+ for item in feed[item_key]:
+ if 'where' not in item and "georss_point" not in item \
+ and 'georss_line' not in item \
and not ("geo_lat" in item and "geo_long" in item):
continue
cls = None
dct = {'origin': self.importer_instance.origin,
'license': self.importer_instance.license}
- if 'georss_point' in item or "geo_lat" in item:
+ if "where" in item and 'coordinates' in item['where']:
+ coord = item['where']['coordinates']
+ if item['where']['type'] == 'Point':
+ cls = Marker
+ dct['point'] = 'SRID=4326;POINT(%s %s)' % (
+ coord[0], coord[1])
+ elif item['where']['type'] == 'LineString':
+ cls = Route
+ dct['route'] = 'SRID=4326;LINESTRING(%s)' % (
+ ",".join(["{} {}".format(c[0], c[1]) for c in coord]))
+ else:
+ continue
+ elif 'georss_point' in item or "geo_lat" in item:
cls = Marker
if 'georss_point' in item:
try:
@@ -692,12 +709,7 @@ class GeoRSSManager(ImportManager):
y = item['geo_lat']
x = item['geo_long']
dct['point'] = 'SRID=4326;POINT(%s %s)' % (x, y)
- if self.importer_instance.get_description:
- for k in ['description', 'summary', 'value']:
- if k in item:
- dct['description'] = item[k]
- break
- else:
+ elif "georss_line" in item:
cls = Route
points = item['georss_line'].split(' ')
reordered_points = []
@@ -707,6 +719,13 @@ class GeoRSSManager(ImportManager):
points[idx * 2]))
dct['route'] = 'SRID=4326;LINESTRING(%s)' % \
",".join(reordered_points)
+ else:
+ continue
+ if self.importer_instance.get_description:
+ for k in ['description', 'summary', 'value']:
+ if k in item:
+ dct['description'] = item[k]
+ break
dct['name'] = item['title']
pl_id = item['id'] if 'id' in item else item['title']
diff --git a/requirements.txt b/requirements.txt
index 37178db..9b5ca45 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,7 +5,7 @@ Pillow
lxml
south>=0.7.3,<0.7.99
simplejson
-feedparser
+feedparser==5.2.1
django-tinymce
icalendar==3.8
chardet==2.3