Ver Fonte

Version 0.7
- Creates a Addressbook file on demand now.
- NA Vcards will be named by displayLabel if present in DB



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

devnull há 4 anos atrás
pai
commit
1813880656
2 ficheiros alterados com 31 adições e 8 exclusões
  1. 29 6
      ContactRestore.py
  2. 2 2
      SQL/Abfragen.sql

+ 29 - 6
ContactRestore.py

@@ -10,7 +10,7 @@
 #  Pytho vobject: http://eventable.github.io/vobject/
 
 # Version
-version=0.6
+version=0.7
 
 # ChangeLog
 #  2021-08-03 - 0.1 - multiple E-Mails with different types are working correctly
@@ -20,6 +20,7 @@ version=0.6
 #                   - 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
+#  2021-10-14 - 0.7 - output to one file 
 
 import sqlite3
 import vobject
@@ -44,7 +45,8 @@ def setDefault(var, default):
 
 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")
-parser.add_argument('--output','-o',required=True, help="Output directory for vcf files")
+parser.add_argument('--output','-o',required=True, help="Output directory for vcf files.'")
+parser.add_argument('--outsinglefile','-f',required=False,help="If specefied, a file with that name is created under specified path, contianing all VCard entrie. E.G. your address book")
 parser.add_argument('--avatars','-a',required=False, help='Avatar directory. If present otherwise we skip this block of avatars, means, no avatars at all')
 parser.add_argument('--debug',action="store_true",help="debugging output to identify problems")
 parser.add_argument('--version', action='version', version='%(prog)s ' + str(version))
@@ -52,10 +54,20 @@ args = parser.parse_args()
 
 
 
-SQLconn = sqlite3.connect(args.db)
-SQLconn.row_factory = sqlite3.Row #das macht den Unterschied und liefert die Werte
 
 try:
+    SQLconn = sqlite3.connect(args.db)
+    SQLconn.row_factory = sqlite3.Row #das macht den Unterschied und liefert die Werte
+    
+    # only this, when fullfile is specified:
+    if args.outsinglefile is not None:
+        outfile=args.outsinglefile.replace(" ","_").replace("(","").replace(")","").replace(",","")
+        ofile = open(outfile,'w')
+        osf=True
+    else:
+        osf=False
+
+
     SQLContCur = SQLconn.cursor()
     SQLContCur.execute('SELECT * FROM Contacts')
     rows = SQLContCur.fetchall()
@@ -67,9 +79,13 @@ try:
             contactID=setDefault(row['contactId'],"NA")
             familyN=setDefault(row['lastName'],"NA")
             givenN=setDefault(row['firstName'],"NA")
+            FullLabel=setDefault(row['displayLabel'],"NA")
             
-            if familyN != None and givenN != None:
+            if (familyN == "NA" and givenN == "NA") and FullLabel != "NA":
+                fullN = FullLabel
+            else:
                 fullN = givenN + " " + familyN
+                
             
             #fullN=setDefault(row['displayLabel'],"NA")
             cardfile=args.output + "/" + fullN.replace(" ","_").replace("(","").replace(")","").replace(".","").replace(",","") + ".vcf"
@@ -85,7 +101,7 @@ try:
             
             
             print("exporting " + fullN + " to file " + cardfile)
-            DEBUG(args.debug,"Contact " + str(fullN) + " family-name=" + str(familyN) + " given-name=" + str(givenN))
+            DEBUG(args.debug,"Contact " + str(fullN) + " family-name=" + str(familyN) + " given-name=" + str(givenN) + " displayLabel=" + str(FullLabel))
             
             # abfrage der Adressdaten
             SQLADRCur = SQLconn.cursor()
@@ -273,6 +289,13 @@ try:
             f.write(vcf.serialize())
             f.close()
 
+            if osf:
+                ofile.write(vcf.serialize())
+                
+    # finally we close the general file
+    if osf:
+        ofile.close()
+                
 # hier brauchen wir einige eception handles -> wie bekommen wir die einzelnen exceptions heruas ?
 #except:
     #print("Error in executing SQL")

+ 2 - 2
SQL/Abfragen.sql

@@ -1,11 +1,11 @@
 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 * from PhoneNumbers JOIN Details on Details.detailId = PhoneNumbers.detailId where PhoneNumbers.contactId = 4;
 SELECT imageURL from Avatars where contactId = 8;