2 # -*- coding: utf-8 -*-
4 from vobject import readComponents
6 from address import Address
7 from geohash import encode
9 for arg in sys.argv[1:]:
16 (cards,query) = argument.split('?')
17 (key, name) = query.split(':')
18 with open(cards, 'r') as f:
22 # Scan for the correct card
25 for card in readComponents(card_data):
27 if key in card.contents.keys():
28 if name.decode('utf-8') == card.contents[key][0].value[0]:
30 if key == 'firstname':
31 if name.decode('utf-8') == card.n.value.given:
34 if name.decode('utf-8') == card.n.value.family:
38 print query+' failed in '+cards
40 # when card is found parse it to docbook.
43 if 'n' in found.contents.keys():
45 empty = n.prefix == '' and n.given == '' and \
46 n.additional =='' and n.family =='' and n.suffix == ''
50 pn += '<honorific>'+n.prefix+'</honorific> '
52 pn += '<firstname>'+n.given+'</firstname> '
53 if n.additional != '':
54 pn += '<othername>'+n.additional+'</othername> '
56 pn += '<surname>'+n.family+'</surname> '
58 pn += '<lineage>'+n.suffix+'</lineage> '
62 if 'adr' in found.contents.keys():
63 for a, t in zip(found.contents['adr'],found.contents['tel']):
64 ad += '\n<address type="'+a.type_param+'"> '
65 if a.value.street != '':
66 ad += '<street>'+a.value.street+'</street>'
67 if a.value.code != '':
68 ad += '<postcode>'+a.value.code+'</postcode> '
69 if a.value.city != '':
70 ad += '<city>'+a.value.city+'</city>'
71 if a.value.country != '':
72 ad += '<country>'+a.value.country+'</country>'
74 ad += '<phone>'+t.value+'</phone>'
76 geostr = u''+a.value.street+', '+a.value.city+', '+a.value.country
77 (lat,lon) = geocode(geostr.encode('utf-8'))
78 mapimage([(float(lat),float(lon))])
79 ad += maplink(lat,lon)
82 if 'org' in found.contents.keys():
85 <orgname>'''+found.org.value[0]+'''</orgname>
91 if 'url' in found.contents.keys():
92 url += '<uri type="website"><link xlink:href="'+found.url.value+'"/></uri> '
95 #if 'geo' in found.contents.keys():
96 # (lat,lon) = found.geo.value.split(';')
97 # mapimage([(float(lat),float(lon))])
99 # geo += maplink(lat,lon)
102 # Turn off email for now
104 #if 'email' in found.contents.keys():
105 # email += '<email>'+found.email.value+'</email>'
108 content = pn+o+url+geo+email
111 content = '<person>'+pn+ad+url+geo+email+'</person>'
113 content = '<person>'+pn+'<affiliation>'+o+'</affiliation>'+url+geo+email+ \
116 <para xmlns="http://docbook.org/ns/docbook"
117 xmlns:xlink="http://www.w3.org/1999/xlink">
124 <street>Street</street>
125 <postcode>Postcode</postcode> <city>City</city>
126 <country>Country</country>
127 <phone>+1 123 456 789</phone>
130 <jobtitle>Occupation</jobtitle>
132 <orgname>Organization</orgname>
134 <street>Street</street>
135 <postcode>Postcode</postcode> <city>City</city>
136 <country>Country</country>
137 <phone>+1 123 456 789</phone>
145 sys.stdout.write(out.encode('utf-8'))