From 5117e854903c77c2e930e26e80d1eecb0a2951f0 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 20 Sep 2016 11:06:29 +0200 Subject: GeoRSS import: manage new version of feedparser --- chimere/tests.py | 2 +- chimere/tests/georss_simple.xml | 8 ++++++++ chimere/utils.py | 37 ++++++++++++++++++++++++++++--------- requirements.txt | 2 +- 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 @@ We just had a big one. 45.256 -71.92 + + M 4.2, Luna Way + + urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6b + 2006-08-17T07:02:32Z + We just had another big one. + 45.256 -110.45 46.46 -109.48 43.84 -109.86 + 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 -- cgit v1.2.3