Created
April 16, 2014 17:42
-
-
Save rubdos/10912284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sqlite3 | |
conn = sqlite3.connect("trackerbackup") | |
c = conn.cursor() | |
vcard = open("contacts.vcard","w+") | |
PersonContacts = [] | |
for r in c.execute("SELECT * FROM 'nco:PersonContact'"): | |
ID = r[0] | |
if(ID == None): | |
continue | |
name = r[1] | |
firstname = r[3] | |
if(name != None): | |
PersonContacts += [(ID, name, firstname)] | |
for Contact in PersonContacts: | |
phonenumbers = [] | |
affiliations = [] | |
for affiliation in c.execute("SELECT * FROM `nco:PersonContact_nco:hasAffiliation`,`nco:Role_nco:hasPhoneNumber` WHERE `nco:PersonContact_nco:hasAffiliation`.ID=? AND `nco:PersonContact_nco:hasAffiliation`.`nco:hasAffiliation`=`nco:Role_nco:hasPhoneNumber`.ID",(Contact[0],)): | |
affiliations+=[affiliation] | |
for affiliation in affiliations: | |
c.execute("SELECT * FROM 'nco:PhoneNumber' WHERE ID=?", (affiliation[4],)) | |
phonenumbers += [c.fetchone()[1]] | |
if len(phonenumbers) > 0: | |
vcard.write("BEGIN:VCARD\nVERSION:3.0\n") | |
vcard.write("N:" + Contact[1]) | |
if(Contact[2] != None): | |
vcard.write(";" + Contact[2]) | |
vcard.write("\n") | |
for phone in phonenumbers: | |
print(phone) | |
vcard.write("TEL;TYPE=HOME,VOICE:"+str(phone) + "\n") | |
vcard.write("END:VCARD\n") | |
#for r in c.execute("SELECT * FROM 'nco:PhoneNumber' WHERE 'nco:PhoneNumber:graph'=?", (phoneID,)): | |
# print(r) | |
conn.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment