--- /dev/null
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from vobject import readComponents
+import sys
+
+for arg in sys.argv[1:]:
+ al = arg.split("=")
+ if al[0] == "lang":
+ lang = al[1]
+ if al[0] == "xptr":
+ argument = al[1]
+
+(cards,query) = argument.split('?')
+(key, name) = query.split(':')
+with open(cards, 'r') as f:
+ card_data = f.read()
+f.closed
+
+# Scan for the correct card
+found = None
+out = u''
+for card in readComponents(card_data):
+# card.prettyPrint()
+ if key in card.contents.keys():
+ if name.decode('utf-8') == card.contents[key][0].value[0]:
+ found = card
+ if key == 'firstname':
+ if name.decode('utf-8') == card.n.value.given:
+ found = card
+ if key == 'surname':
+ if name.decode('utf-8') == card.n.value.family:
+ found = card
+
+if not found:
+ print query+' failed in '+cards
+ exit(2)
+# when card is found parse it to docbook.
+pn = ''
+
+if 'n' in found.contents.keys():
+ n = found.n.value
+ empty = n.prefix == '' and n.given == '' and \
+ n.additional =='' and n.family =='' and n.suffix == ''
+ if not empty:
+ pn += '<personname>'
+ if n.prefix != '':
+ pn += '<honorific>'+n.prefix+'</honorific>'
+ if n.given != '':
+ pn += '<firstname>'+n.given+'</firstname>'
+ if n.additional != '':
+ pn += '<othername>'+n.additional+'</othername>'
+ if n.family != '':
+ pn += '<surname>'+n.family+'</surname>'
+ if n.suffix != '':
+ pn += '<lineage>'+n.suffix+'</lineage>'
+ pn += '</personname>'
+
+ad = ''
+if 'adr' in found.contents.keys():
+ for a, t in zip(found.contents['adr'],found.contents['tel']):
+ ad += '\n<address type="'+a.type_param+'">'
+ if a.value.street != '':
+ ad += '<street>'+a.value.street+'</street>'
+ if a.value.code != '':
+ ad += '<postcode>'+a.value.code+'</postcode>'
+ if a.value.city != '':
+ ad += '<city>'+a.value.city+'</city>'
+ if a.value.country != '':
+ ad += '<country>'+a.value.country+'</country>'
+ if t.value != '':
+ ad += '<phone>'+t.value+'</phone>'
+ ad += '</address>'
+
+o = ''
+if 'org' in found.contents.keys():
+ o = '''
+ <org>
+ <orgname>'''+found.org.value[0]+'''</orgname>
+ '''+ad+'''
+ </org>'''
+
+
+url = ''
+if 'url' in found.contents.keys():
+ url += '<uri type="website"><link xlink:href="'+found.url.value+'"/></uri>'
+geo = ''
+if 'geo' in found.contents.keys():
+ (lat,lon) = found.geo.value.split(';')
+ geo += '<uri type="location"><link xlink:href="http://www.openstreetmap.org/'+ \
+ '?mlat='+lat+'&mlon='+lon+'&zoom=18&layers=M">geo:'+lat+','+lon+'</link></uri>'
+
+# Turn off email for now
+email = ''
+#if 'email' in found.contents.keys():
+# email += '<email>'+found.email.value+'</email>'
+
+if empty:
+ content = pn+o+url+geo+email
+else:
+ if o == '':
+ content = '<person>'+pn+ad+url+geo+email+'</person>'
+ else:
+ content = '<person>'+pn+'<affiliation>'+o+'</affiliation>'+url+geo+email+ \
+ '</person>'
+out = '''
+<para xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink">
+ '''+content+'''
+</para>
+'''
+
+ex ='''
+ <address>
+ <street>Street</street>
+ <postcode>Postcode</postcode> <city>City</city>
+ <country>Country</country>
+ <phone>+1 123 456 789</phone>
+ </address>
+ <affiliation>
+ <jobtitle>Occupation</jobtitle>
+ <org>
+ <orgname>Organization</orgname>
+ <address>
+ <street>Street</street>
+ <postcode>Postcode</postcode> <city>City</city>
+ <country>Country</country>
+ <phone>+1 123 456 789</phone>
+ </address>
+ </org>
+ </affiliation>
+ </person>
+</para>
+'''
+
+sys.stdout.write(out.encode('utf-8'))