2 # -*- coding: utf-8 -*-
4 from vobject import readComponents
6 from addr import mapimage, geocode
7 from geohash import encode
12 mnt,sec = divmod(ns*3600,60)
13 deg,mnt = divmod(mnt,60)
14 out = u'''%d°%2d'%5.2f"%s''' % ( deg,mnt,sec,'N')
15 mnt,sec = divmod(ew*3600,60)
16 deg,mnt = divmod(mnt,60)
17 out += u''' %d°%2d'%05.2f"%s''' % ( deg,mnt,sec,'E')
25 "http://www.openstreetmap.org/?mlat=%s&mlon=%s&zoom=18&layers=M">
27 <imageobject condition="web">
28 <imagedata fileref="%s.png" format="PNG"/>
31 <phrase>geo:%s,%s</phrase>
37 ''' % (lat, lon, encode(float(lat), float(lon)), lat, lon, coord2dms((lat, lon)))
39 for arg in sys.argv[1:]:
47 (cards,query) = argument.split('?')
48 (key, name) = query.split(':')
49 with open(cards, 'r') as f:
53 # Scan for the correct card
56 for card in readComponents(card_data):
58 if key in card.contents.keys():
59 if name.decode('utf-8') == card.contents[key][0].value[0]:
61 if key == 'firstname':
62 if name.decode('utf-8') == card.n.value.given:
65 if name.decode('utf-8') == card.n.value.family:
69 print query+' failed in '+cards
71 # when card is found parse it to docbook.
74 if 'n' in found.contents.keys():
76 empty = n.prefix == '' and n.given == '' and \
77 n.additional =='' and n.family =='' and n.suffix == ''
81 pn += '<honorific>'+n.prefix+'</honorific> '
83 pn += '<firstname>'+n.given+'</firstname> '
84 if n.additional != '':
85 pn += '<othername>'+n.additional+'</othername> '
87 pn += '<surname>'+n.family+'</surname> '
89 pn += '<lineage>'+n.suffix+'</lineage> '
93 if 'adr' in found.contents.keys():
94 for a, t in zip(found.contents['adr'],found.contents['tel']):
95 ad += '\n<address type="'+a.type_param+'"> '
96 if a.value.street != '':
97 ad += '<street>'+a.value.street+'</street>'
98 if a.value.code != '':
99 ad += '<postcode>'+a.value.code+'</postcode> '
100 if a.value.city != '':
101 ad += '<city>'+a.value.city+'</city>'
102 if a.value.country != '':
103 ad += '<country>'+a.value.country+'</country>'
105 ad += '<phone>'+t.value+'</phone>'
107 geostr = u''+a.value.street+', '+a.value.city+', '+a.value.country
108 (lat,lon) = geocode(geostr.encode('utf-8'))
109 mapimage([(float(lat),float(lon))])
110 ad += maplink(lat,lon)
113 if 'org' in found.contents.keys():
116 <orgname>'''+found.org.value[0]+'''</orgname>
122 if 'url' in found.contents.keys():
123 url += '<uri type="website"><link xlink:href="'+found.url.value+'"/></uri> '
126 #if 'geo' in found.contents.keys():
127 # (lat,lon) = found.geo.value.split(';')
128 # mapimage([(float(lat),float(lon))])
130 # geo += maplink(lat,lon)
133 # Turn off email for now
135 #if 'email' in found.contents.keys():
136 # email += '<email>'+found.email.value+'</email>'
139 content = pn+o+url+geo+email
142 content = '<person>'+pn+ad+url+geo+email+'</person>'
144 content = '<person>'+pn+'<affiliation>'+o+'</affiliation>'+url+geo+email+ \
147 <para xmlns="http://docbook.org/ns/docbook"
148 xmlns:xlink="http://www.w3.org/1999/xlink">
155 <street>Street</street>
156 <postcode>Postcode</postcode> <city>City</city>
157 <country>Country</country>
158 <phone>+1 123 456 789</phone>
161 <jobtitle>Occupation</jobtitle>
163 <orgname>Organization</orgname>
165 <street>Street</street>
166 <postcode>Postcode</postcode> <city>City</city>
167 <country>Country</country>
168 <phone>+1 123 456 789</phone>
176 sys.stdout.write(out.encode('utf-8'))