diff options
Diffstat (limited to 'chimere/utils.py')
-rw-r--r-- | chimere/utils.py | 37 |
1 files changed, 28 insertions, 9 deletions
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'] |