Subversion Repositories Sailfish_Contacts_Restore

Compare Revisions

Ignore whitespace Rev 15 → Rev 16

/ContactRestore.py
5,16 → 5,18
#
#
# Links
# Projects Page: https://wiki.siningsoft.de/doku.php?id=sailfishos:projects:sailfish_contacts_rescue
# FileFormatdescription: https://docs.fileformat.com/email/vcf/#vcf-30-example
# Pytho vobject: http://eventable.github.io/vobject/
 
# Version
version=0.3
version=0.4
 
# ChangeLog
# 2021-08-03 - 0.1 - multiple E-Mails with different types are working correctly
# 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
 
import sqlite3
import vobject
22,10 → 24,20
import argparse
import os
 
#class vobject2(vobject):
 
 
 
def DEBUG(debug,msg):
if debug is True:
print("..DEBUG: " + msg)
 
# will return a default value, when var is None
def setDefault(var, default):
if var is None:
return default
else:
return var
 
parser = argparse.ArgumentParser(description='Restore SailfishOS 3 Contacts', epilog='This script was written to restore SailfishOS 3 contacts as VCF files. To see additional information, visit: https://wiki.siningsoft.de/doku.php?id=sailfishos:projects:sailfish_contacts_rescue' )
parser.add_argument('--db','-d', required=True, help="Sqlite3 Database file usually /home/{nemo,defaultuser}/.local/share/system/Contacts/qtcontacts-sqlite/contacts.db")
45,11 → 57,11
for row in SQLContCur.execute('SELECT * FROM Contacts'):
# contactID abfragen
contactID=row[0]
familyN=row[6]
givenN=row[4]
fullN=row[1]
cardfile=args.output + "/" + fullN.replace(" ","_") + ".vcf"
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"
# wir erstellen das Objekt
62,7 → 74,7
print("exporting " + fullN + " to file " + cardfile)
DEBUG(args.debug,"Contact " + fullN)
DEBUG(args.debug,"Contact " + str(fullN) + " family-name=" + str(familyN) + " given-name=" + str(givenN))
# abfrage der Adressdaten
SQLADRCur = SQLconn.cursor()
71,30 → 83,40
if ADRrow[2] is not None:
ADRstr=str(ADRrow[2])
else:
ADRstr=""
ADRstr="NA"
 
if ADRrow[5] is not None:
ADRcit=str(ADRrow[5])
#.replace(" ","\ ").replace("\\", "\\\\").replace(";", "\;").replace(",", "\,")
 
else:
ADRcit=""
ADRcit="NA"
if ADRrow[4] is not None:
ADRreg=str(ADRrow[4])
else:
ADRreg=""
ADRreg="NA"
 
if ADRrow[6] is not None:
ADRcod=str(ADRrow[6])
else:
ADRcod=""
ADRcod="NA"
 
if ADRrow[7] is not None:
ADRcou=str(ADRrow[7])
else:
ADRcou=""
ADRcou="NA"
 
DEBUG(args.debug,"Addressdata: street=" + ADRstr + " city=" + ADRcit + " region=" + ADRreg + " code=" + ADRcod + " country=" + ADRcou)
adr = vcf.add('ADR').value = vobject.vcard.Address(street=ADRstr, city=ADRcit, region=ADRreg, code=ADRcod,country=ADRcou)
# we need to know the context we've read here
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()
 
DEBUG(args.debug,"Addressdata: street=" + ADRstr + " city=" + ADRcit + " region=" + ADRreg + " code=" + ADRcod + " country=" + ADRcou + " context=" + str(ADRrow[14]))
## Abfragen Organisation
SQLORGCur = SQLconn.cursor()
/SQL/Abfragen.sql
1,3 → 1,5
SELECT * FROM Contacts;
SELECT * FROM Contacts JOIN EmailAddresses ON Contacts.contactId = EmailAddresses.contactId;
SELECT * from PhoneNumbers JOIN Details on Details.detailId = PhoneNumbers.detailId;
SELECT * FROM Contacts JOIN Addresses ON Contacts.contactId = Addresses.contactId WHERE displayLabel like '%oduma%';
SELECT * FROM Addresses JOIN Details on Details.detailId=Addresses.contactId WHERE Addresses.contactId=5;
/Testdata/Output/Ludowig_Adressuser.vcf
1,6 → 1,6
BEGIN:VCARD
VERSION:3.0
UID:4c7322e6-1d4f-4507-bb0b-67225cf6d6d4
UID:271b6ea1-178e-4f0a-9797-45659d1d8f9c
ADR:;;privateParcelStreet 1;pPC;pPR;12345;pPCo
ADR:;;POSTAL;;;;
ADR:;;DOMESTIC;;;;
/Testdata/Output/Maik_Mustermann.vcf
File deleted
/Testdata/Output/SiSo_Emulator.vcf
1,6 → 1,6
BEGIN:VCARD
VERSION:3.0
UID:819b17b0-5d94-4589-88c8-8fb04c083512
UID:6ecad6a1-9955-47ae-8d26-91111e54c332
EMAIL:sailfish@siningsoft.de
EMAIL:sailfishdev@siningsoft.de
FN:SiSo Emulator
/doc/ToDo.txt
2,5 → 2,14
----
 
- Address Typ wird nicht gesetzt
- Foto Base64 Encoding wird nicht gesetzt
-
- Python logger einbeziehen:
# ------------------------------------ Logging ---------------------------------
logger = logging.getLogger(__name__)
if not logging.getLogger().handlers:
handler = logging.StreamHandler()
formatter = logging.Formatter('%(name)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.ERROR) # Log errors
DEBUG = False # Don't waste time on debug calls