/venus

To download this project, use:
bzr branch http://golem.ph.utexas.edu/~distler/code/venus/

« back to all changes in this revision

Viewing changes to planet/reconstitute.py

  • Committer: Sam Ruby
  • Date: 2008-08-11 12:17:17 UTC
  • mfrom: (86.1.1 venus)
  • Revision ID: rubys@intertwingly.net-20080811121717-9bpq6zq0tg267oz5
Add test case

Show diffs side-by-side

added added

removed removed

186
186
 
187
187
    xentry.appendChild(xcontent)
188
188
 
 
189
def location(xentry, long, lat):
 
190
    """ insert geo location into the entry """
 
191
    if not lat or not long: return
 
192
 
 
193
    xlat = createTextElement(xentry, '%s:%s' % ('geo','lat'), '%f' % lat)
 
194
    xlat.setAttribute('xmlns:%s' % 'geo', 'http://www.w3.org/2003/01/geo/wgs84_pos#')
 
195
    xlong = createTextElement(xentry, '%s:%s' % ('geo','long'), '%f' % long)
 
196
    xlong.setAttribute('xmlns:%s' % 'geo', 'http://www.w3.org/2003/01/geo/wgs84_pos#')
 
197
 
 
198
    xentry.appendChild(xlat)
 
199
    xentry.appendChild(xlong)
 
200
 
189
201
def source(xsource, source, bozo, format):
190
202
    """ copy source information to the entry """
191
203
    xdoc = xsource.ownerDocument
259
271
                entry['%s_%s' % (ns,name.lower())])
260
272
            xoriglink.setAttribute('xmlns:%s' % ns, feed.namespaces[ns])
261
273
 
 
274
    # geo location
 
275
    if entry.has_key('where') and \
 
276
        entry.get('where',[]).has_key('type') and \
 
277
        entry.get('where',[]).has_key('coordinates'):
 
278
        where = entry.get('where',[])
 
279
        type = where.get('type',None)
 
280
        coordinates = where.get('coordinates',None)
 
281
        if type == 'Point':
 
282
            location(xentry, coordinates[0], coordinates[1])
 
283
        elif type == 'Box' or type == 'LineString' or type == 'Polygon':
 
284
            location(xentry, coordinates[0][0], coordinates[0][1])
 
285
    if entry.has_key('geo_lat') and \
 
286
        entry.has_key('geo_long'):
 
287
        location(xentry, (float)(entry.get('geo_long',None)), (float)(entry.get('geo_lat',None)))
 
288
 
262
289
    # author / contributor
263
290
    author_detail = entry.get('author_detail',{})
264
291
    if author_detail and not author_detail.has_key('name') and \