Parcourir la source

DEBUG working
problems with NullValues in Addresses fixed
version introduced


git-svn-id: svn://svn.siningsoft.de/Sailfish_Contacts_Restore@11 9ea9dde1-eeb2-4aae-9f27-8a0df3aa35ee

devnull il y a 4 ans
Parent
commit
d01e227545
2 fichiers modifiés avec 41 ajouts et 8 suppressions
  1. 40 7
      ContactRescue.py
  2. 1 1
      SQL/Abfragen.sql

+ 40 - 7
ContactRescue.py

@@ -1,3 +1,4 @@
+#!/usr/bin/python3
 # coding=utf-8
 # Doc
 #  Script to extract Contacts from Sailfish Contact SQLite DB located at 
@@ -7,8 +8,12 @@
 #  FileFormatdescription: https://docs.fileformat.com/email/vcf/#vcf-30-example
 #  Pytho vobject: http://eventable.github.io/vobject/
 
+# Version
+version=0.2
+
 # ChangeLog
-#  2021-08-03 - multiple E-Mails with different types are working correctly
+#  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
 
 import sqlite3
 import vobject
@@ -21,9 +26,10 @@ def DEBUG(debug,msg):
 
 
 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', help="Sqlite3 Database file usually /home/{nemo,defaultuser)/.local/share/system/Contacts/qtcontacts-sqlite/contacts.db")
-parser.add_argument('--output','-o',help="Output directory for vcf files")
+parser.add_argument('--db','-d', required=True, help="Sqlite3 Database file usually /home/{nemo,defaultuser)/.local/share/system/Contacts/qtcontacts-sqlite/contacts.db")
+parser.add_argument('--output','-o',required=True, help="Output directory for vcf files")
 parser.add_argument('--debug',action="store_true",help="debugging output to identify problems")
+parser.add_argument('--version', action='version', version='%(prog)s ' + str(version))
 args = parser.parse_args()
 
 
@@ -48,10 +54,37 @@ try:
             
             DEBUG(args.debug,"Contact " + row[1])
             
-            
+            # abfrage der Adressdaten
             SQLADRCur = SQLconn.cursor()
             for ADRrow in SQLADRCur.execute('SELECT * FROM Addresses JOIN Details on Details.detailId = Addresses.detailId where Addresses.contactId = ' + str(contactID)):
-                adr = vcf.add('ADR').value = vobject.vcard.Address(street=ADRrow[2], city=ADRrow[5], region=ADRrow[4], code=ADRrow[6],country=ADRrow[7])
+            
+                if ADRrow[2] is not None:
+                    ADRstr=str(ADRrow[2])
+                else:
+                    ADRstr=""
+
+                if ADRrow[5] is not None:
+                    ADRcit=str(ADRrow[5])
+                else:
+                    ADRcit=""
+                                    
+                if ADRrow[4] is not None:
+                    ADRreg=str(ADRrow[4])
+                else:
+                    ADRreg=""
+
+                if ADRrow[6] is not None:
+                    ADRcod=str(ADRrow[6])
+                else:
+                    ADRcod=""
+
+                if ADRrow[7] is not None:
+                    ADRcou=str(ADRrow[7])
+                else:
+                    ADRcou=""
+
+                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)
             
             ## Abfragen Organisation
             SQLORGCur = SQLconn.cursor()
@@ -108,7 +141,7 @@ try:
                 
                 
                 # debug ausgabe
-                print("...debug: " + str(Phonerow[2]) + " at " + str(Phonerow[10]) + " subtype=" + str(Phonerow[3]))
+                DEBUG(args.debug,str(Phonerow[2]) + " at " + str(Phonerow[10]) + " subtype=" + str(Phonerow[3]))
                 
                 # None is a normal phone Number
 
@@ -126,7 +159,7 @@ try:
                 elif Phonerow[3] is None:
                     phcat='voice'
                 
-                print("...debug: " + phcat)
+                DEBUG(args.debug,phcat)
 
                 phone = vcf.add(phcat).value = str(Phonerow[2])
                 

+ 1 - 1
SQL/Abfragen.sql

@@ -1,4 +1,4 @@
 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 Addresses JOIN Details on Details.detailId = Addresses.detailId where contactId = 3;
+SELECT * FROM Addresses JOIN Details on Details.detailId = Addresses.detailId where Addresses.contactId = 6;