From 9b3290832eabbc01e6deccd6202a8e26b9ec507d Mon Sep 17 00:00:00 2001 From: Fredrik Unger Date: Wed, 16 May 2012 11:44:41 +0200 Subject: [PATCH] Switching to address based map generation. Divided to subroutines. The generation was geo: tag based but as there is only one tag per vcard I switched to address lookup instead. There are problems with CZ village addresses, and some missing address tags that has to be added to openstreetmap, but it is a better longterm solution. --- xinclude/contact.py | 47 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/xinclude/contact.py b/xinclude/contact.py index 879fd66..379a336 100755 --- a/xinclude/contact.py +++ b/xinclude/contact.py @@ -3,6 +3,38 @@ from vobject import readComponents import sys +from addr import mapimage, geocode +from geohash import encode + +def coord2dms(coord): + ns = coord[0] + ew = coord[1] + mnt,sec = divmod(ns*3600,60) + deg,mnt = divmod(mnt,60) + out = u'''%d°%2d'%5.2f"%s''' % ( deg,mnt,sec,'N') + mnt,sec = divmod(ew*3600,60) + deg,mnt = divmod(mnt,60) + out += u''' %d°%2d'%05.2f"%s''' % ( deg,mnt,sec,'E') + return out + + +def maplink(lat,lon): + return ''' + + + + + + + + geo:%s,%s + + + %s + + +''' % (lat, lon, encode(float(lat), float(lon)), lat, lon, coord2dms((lat, lon))) for arg in sys.argv[1:]: al = arg.split("=") @@ -11,6 +43,7 @@ for arg in sys.argv[1:]: if al[0] == "xptr": argument = al[1] + (cards,query) = argument.split('?') (key, name) = query.split(':') with open(cards, 'r') as f: @@ -71,6 +104,10 @@ if 'adr' in found.contents.keys(): if t.value != '': ad += ''+t.value+'' ad += '' + geostr = u''+a.value.street+', '+a.value.city+', '+a.value.country + (lat,lon) = geocode(geostr.encode('utf-8')) + mapimage([(float(lat),float(lon))]) + ad += maplink(lat,lon) o = '' if 'org' in found.contents.keys(): @@ -85,10 +122,12 @@ url = '' if 'url' in found.contents.keys(): url += '' geo = '' -if 'geo' in found.contents.keys(): - (lat,lon) = found.geo.value.split(';') - geo += 'geo:'+lat+','+lon+'' +#if 'geo' in found.contents.keys(): +# (lat,lon) = found.geo.value.split(';') +# mapimage([(float(lat),float(lon))]) +# # create picture +# geo += maplink(lat,lon) + # Turn off email for now email = '' -- 2.30.2