Subversion Repositories Sailfish_Contacts_Restore

Compare Revisions

Ignore whitespace Rev 17 → Rev 16

/ContactRestore.py
10,7 → 10,7
# Pytho vobject: http://eventable.github.io/vobject/
 
# Version
version=0.6
version=0.4
 
# ChangeLog
# 2021-08-03 - 0.1 - multiple E-Mails with different types are working correctly
17,9 → 17,6
# 2021-08-09 - 0.2 - Phonenumbers with parameters, Addresses with parameters, E-Mail-Addresses with marameters
# 2021-08-10 - 0.3 - load Avatars into VCards
# 2021-08-28 - 0.4 - bugfixing after full exporting my contacts
# - Address export fixing
# 2021-09-18 - 0.5 - bugfixing wrong table column mapping
# 2021-09-21 - 0.6 - changing table mapping, adding fix for phonenumber categories
 
import sqlite3
import vobject
53,25 → 50,17
 
 
SQLconn = sqlite3.connect(args.db)
SQLconn.row_factory = sqlite3.Row #das macht den Unterschied und liefert die Werte
 
 
try:
SQLContCur = SQLconn.cursor()
SQLContCur.execute('SELECT * FROM Contacts')
rows = SQLContCur.fetchall()
for row in rows:
for row in SQLContCur.execute('SELECT * FROM Contacts'):
 
# contactID abfragen
contactID=setDefault(row['contactId'],"NA")
familyN=setDefault(row['lastName'],"NA")
givenN=setDefault(row['firstName'],"NA")
if familyN != None and givenN != None:
fullN = givenN + " " + familyN
#fullN=setDefault(row['displayLabel'],"NA")
contactID=setDefault(row[0],"NA")
familyN=setDefault(row[6],"NA")
givenN=setDefault(row[4],"NA")
fullN=setDefault(row[1],"NA")
cardfile=args.output + "/" + fullN.replace(" ","_").replace("(","").replace(")","").replace(".","").replace(",","") + ".vcf"
89,42 → 78,40
# abfrage der Adressdaten
SQLADRCur = SQLconn.cursor()
SQLADRCur.execute('SELECT * FROM Addresses JOIN Details on Addresses.detailId = Details.detailId where Addresses.contactId = ' + str(contactID))
ADRrows = SQLADRCur.fetchall()
for ADRrow in ADRrows:
for ADRrow in SQLADRCur.execute('SELECT * FROM Addresses JOIN Details on Details.detailId = Addresses.detailId where Addresses.contactId = ' + str(contactID)):
if ADRrow['street'] is not None:
ADRstr=str(ADRrow['street'])
if ADRrow[2] is not None:
ADRstr=str(ADRrow[2])
else:
ADRstr="NA"
 
if ADRrow['locality'] is not None:
ADRcit=str(ADRrow['locality'])
if ADRrow[5] is not None:
ADRcit=str(ADRrow[5])
#.replace(" ","\ ").replace("\\", "\\\\").replace(";", "\;").replace(",", "\,")
 
else:
ADRcit="NA"
if ADRrow['region'] is not None:
ADRreg=str(ADRrow['region'])
if ADRrow[4] is not None:
ADRreg=str(ADRrow[4])
else:
ADRreg="NA"
 
if ADRrow['postCode'] is not None:
ADRcod=str(ADRrow['postCode'])
if ADRrow[6] is not None:
ADRcod=str(ADRrow[6])
else:
ADRcod="NA"
 
if ADRrow['country'] is not None:
ADRcou=str(ADRrow['country'])
if ADRrow[7] is not None:
ADRcou=str(ADRrow[7])
else:
ADRcou="NA"
 
# we need to know the context we've read here
# 2021-09-19 - it figured out, that this might cause a call of AddressBehaviour for Address.replace(***)
#if ADRrow[14] is not None:
# addADR="ADR;TYPE="+str(ADRrow[14])
#else:
# addADR="ADR"
if ADRrow[14] is not None:
addADR="ADR;TYPE="+str(ADRrow[14])
else:
addADR="ADR"
 
vcf.add("ADR").value = vobject.vcard.Address(street=ADRstr, city=ADRcit, region=ADRreg, code=ADRcod,country=ADRcou)
#adr = vcf.add(addADR).value = vobject.vcard.Address()
133,17 → 120,14
## Abfragen Organisation
SQLORGCur = SQLconn.cursor()
SQLORGCur.execute('SELECT * from Organizations where contactId = ' + str(contactID))
ORGrows = SQLContCur.fetchall()
for ORGrow in ORGrows:
org = vcf.add('ORG').value = [str(ORGrow['name']), str(ORGrow['department'])]
for ORGrow in SQLORGCur.execute('SELECT * from Organizations where contactId = ' + str(contactID)):
org = vcf.add('ORG').value = [str(ORGrow[2]), str(ORGrow[6])]
if ORGrow[4] is not None:
title = vcf.add('TITLE').value = str(ORGrow['title'])
title = vcf.add('TITLE').value = str(ORGrow[4])
if ORGrow[3] is not None:
role = vcf.add('ROLE').value = str(ORGrow['role'])
role = vcf.add('ROLE').value = str(ORGrow[3])
# Also parameters are possible. Could be read out
# | columnID | column |
161,26 → 145,23
## Abfragen E-Mail-Adressen
SQLEmailCur = SQLconn.cursor()
SQLEmailCur.execute('SELECT * from EmailAddresses JOIN Details on Details.detailId= EmailAddresses.detailId where EmailAddresses.contactId = ' + str(contactID))
Emailrows = SQLEmailCur.fetchall()
for Emailrow in Emailrows:
for Emailrow in SQLEmailCur.execute('SELECT * from EmailAddresses JOIN Details on Details.detailId= EmailAddresses.detailId where EmailAddresses.contactId = ' + str(contactID)):
# debug ausgabe
DEBUG(args.debug,str(Emailrow[2]) + " at " + str(Emailrow[9]))
email = vcf.add('email')
email.value = str(Emailrow['emailAddress'])
email.value = str(Emailrow[2])
# nur den Typ einpflegen, wenn das hier nicht none ist
if Emailrow['contexts'] != None:
email.type_param = str(Emailrow['contexts'])
if Emailrow[9] != None:
email.type_param = str(Emailrow[9])
 
 
SQLPhoneCur = SQLconn.cursor()
SQLPhoneCur.execute('SELECT * from PhoneNumbers JOIN Details on Details.detailId = PhoneNumbers.detailId where PhoneNumbers.contactId = ' + str(contactID))
Phonerows = SQLPhoneCur.fetchall()
## Abfragen Telefonnummer, Fax, SMS - Nummern kommen aus der gleichen Tabelle
for Phonerow in Phonerows:
for Phonerow in SQLPhoneCur.execute('SELECT * from PhoneNumbers JOIN Details on Details.detailId = PhoneNumbers.detailId where PhoneNumbers.contactId = ' + str(contactID)):
# wir müssen die SubTypen unterscheiden
#Null voice
195,35 → 176,28
# None is a normal phone Number
 
 
if Phonerow['subTypes'] == "1":
if Phonerow[3] == "1":
phcat='cell'
elif Phonerow['subTypes'] == "2":
elif Phonerow[3] == "2":
phcat='fax'
elif Phonerow['subTypes'] == "3":
elif Phonerow[3] == "3":
phcat='pager'
elif Phonerow['subTypes'] == "6":
elif Phonerow[3] == "6":
phcat='video'
elif Phonerow['subTypes'] == "10":
elif Phonerow[3] == "10":
phcat='assistent'
elif Phonerow['subTypes'] is None:
elif Phonerow[3] is None:
phcat='voice'
# debug ausgabe
DEBUG(args.debug,str(Phonerow['phoneNumber']) + " at " + str(Phonerow['contexts']) + " as subtype=" + str(Phonerow['subTypes']) + "=" + phcat)
DEBUG(args.debug,str(Phonerow[2]) + " at " + str(Phonerow[10]) + " as subtype=" + str(Phonerow[3]) + "=" + phcat)
 
phaddcat = 'TEL;TYPE='+phcat;
 
# nur den Typ einpflegen, wenn das hier nicht none ist
if Phonerow['contexts'] != None:
phaddcat = phaddcat + "," + Phonerow['contexts']
 
phone = vcf.add(phaddcat).value = str(Phonerow['phoneNumber'])
phone = vcf.add(phcat).value = str(Phonerow[2])
# nur den Typ einpflegen, wenn das hier nicht none ist
if Phonerow['contexts'] != None:
if Phonerow[10] != None:
try:
phone.type_param = str(Phonerow['contexts'])
phone.type_param = str(Phonerow[10])
except AttributeError:
continue
 
231,11 → 205,9
if args.avatars is not None:
DEBUG(args.debug,"Avatar Argument given")
SQLAVTRCur = SQLconn.cursor()
SQLAVTRCur.execute('SELECT imageURL from Avatars where contactId = ' + str(contactID))
AVTRrows = SQLAVTRCur.fetchall()
## get Avatar Filelink from DB
for AVTRrow in AVTRrows:
for AVTRrow in SQLAVTRCur.execute('SELECT imageURL from Avatars where contactId = ' + str(contactID)):
DEBUG(args.debug,"found PHOTO entry")
/SQL/Abfragen.sql
1,11 → 1,5
SELECT * FROM Contacts;
SELECT * FROM Contacts JOIN EmailAddresses ON Contacts.contactId = EmailAddresses.contactId;
SELECT * FROM Contacts JOIN PhoneNumbers ON Contacts.contactId = PhoneNumbers.contactId WHERE Contacts.contactId=42;
SELECT * from PhoneNumbers JOIN Details on Details.detailId = PhoneNumbers.detailId;
SELECT * from PhoneNumbers JOIN Details on Details.detailId = PhoneNumbers.detailId WHERE PhoneNumbers.contactId=42;
SELECT * FROM Contacts JOIN Addresses ON Contacts.contactId = Addresses.contactId WHERE displayLabel like '%oduma%';
SELECT * FROM Addresses JOIN Details on Addresses.detailId=Details.detailId WHERE Addresses.contactId=7;
SELECT * from Organizations where contactId = 7;
SELECT * from EmailAddresses JOIN Details on Details.detailId= EmailAddresses.detailId where EmailAddresses.contactId = 8;
SELECT * from PhoneNumbers JOIN Details on Details.detailId = PhoneNumbers.detailId where PhoneNumbers.contactId = 8;
SELECT imageURL from Avatars where contactId = 8;
SELECT * FROM Addresses JOIN Details on Details.detailId=Addresses.contactId WHERE Addresses.contactId=5;
/Testdata/Output/Ludowig_Adressuser.vcf
1,10 → 1,10
BEGIN:VCARD
VERSION:3.0
UID:ccc9635a-782b-49af-b5f5-a194d40f5651
UID:271b6ea1-178e-4f0a-9797-45659d1d8f9c
ADR:;;privateParcelStreet 1;pPC;pPR;12345;pPCo
ADR:;;POSTAL;NA;NA;NA;NA
ADR:;;DOMESTIC;NA;NA;NA;NA
ADR:;;International;NA;NA;NA;NA
ADR:;;POSTAL;;;;
ADR:;;DOMESTIC;;;;
ADR:;;International;;;;
ADR:;;privateStreet 1;privateCity;privateRegion;12345;privateCountry
FN:Ludowig Adressuser
N:Adressuser;Ludowig;;;
/Testdata/Output/Maik_Mustermann.vcf
File deleted
/Testdata/Output/SiSo_Emulator.vcf
1,6 → 1,6
BEGIN:VCARD
VERSION:3.0
UID:3a4ed0fb-0bb4-4c72-9b2d-456b1d910c5b
UID:6ecad6a1-9955-47ae-8d26-91111e54c332
EMAIL:sailfish@siningsoft.de
EMAIL:sailfishdev@siningsoft.de
FN:SiSo Emulator