2 # -*- coding: utf-8 -*-
4 from vobject import readComponents
7 for arg in sys.argv[1:]:
14 (cards,query) = argument.split('?')
15 (key, name) = query.split(':')
16 with open(cards, 'r') as f:
20 # Scan for the correct card
23 for card in readComponents(card_data):
25 if key in card.contents.keys():
26 if name.decode('utf-8') == card.contents[key][0].value[0]:
28 if key == 'firstname':
29 if name.decode('utf-8') == card.n.value.given:
32 if name.decode('utf-8') == card.n.value.family:
36 print query+' failed in '+cards
38 # when card is found parse it to docbook.
41 if 'n' in found.contents.keys():
43 empty = n.prefix == '' and n.given == '' and \
44 n.additional =='' and n.family =='' and n.suffix == ''
48 pn += '<honorific>'+n.prefix+'</honorific>'
50 pn += '<firstname>'+n.given+'</firstname>'
51 if n.additional != '':
52 pn += '<othername>'+n.additional+'</othername>'
54 pn += '<surname>'+n.family+'</surname>'
56 pn += '<lineage>'+n.suffix+'</lineage>'
60 if 'adr' in found.contents.keys():
61 for a, t in zip(found.contents['adr'],found.contents['tel']):
62 ad += '\n<address type="'+a.type_param+'">'
63 if a.value.street != '':
64 ad += '<street>'+a.value.street+'</street>'
65 if a.value.code != '':
66 ad += '<postcode>'+a.value.code+'</postcode>'
67 if a.value.city != '':
68 ad += '<city>'+a.value.city+'</city>'
69 if a.value.country != '':
70 ad += '<country>'+a.value.country+'</country>'
72 ad += '<phone>'+t.value+'</phone>'
76 if 'org' in found.contents.keys():
79 <orgname>'''+found.org.value[0]+'''</orgname>
85 if 'url' in found.contents.keys():
86 url += '<uri type="website"><link xlink:href="'+found.url.value+'"/></uri>'
88 if 'geo' in found.contents.keys():
89 (lat,lon) = found.geo.value.split(';')
90 geo += '<uri type="location"><link xlink:href="http://www.openstreetmap.org/'+ \
91 '?mlat='+lat+'&mlon='+lon+'&zoom=18&layers=M">geo:'+lat+','+lon+'</link></uri>'
93 # Turn off email for now
95 #if 'email' in found.contents.keys():
96 # email += '<email>'+found.email.value+'</email>'
99 content = pn+o+url+geo+email
102 content = '<person>'+pn+ad+url+geo+email+'</person>'
104 content = '<person>'+pn+'<affiliation>'+o+'</affiliation>'+url+geo+email+ \
107 <para xmlns="http://docbook.org/ns/docbook"
108 xmlns:xlink="http://www.w3.org/1999/xlink">
115 <street>Street</street>
116 <postcode>Postcode</postcode> <city>City</city>
117 <country>Country</country>
118 <phone>+1 123 456 789</phone>
121 <jobtitle>Occupation</jobtitle>
123 <orgname>Organization</orgname>
125 <street>Street</street>
126 <postcode>Postcode</postcode> <city>City</city>
127 <country>Country</country>
128 <phone>+1 123 456 789</phone>
136 sys.stdout.write(out.encode('utf-8'))