浏览代码

Version 0.3 including PHOTO base64 encoding into vcard.
Photo Encoding parameter missing


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

devnull 4 年之前
父节点
当前提交
39cab7b737

+ 44 - 3
ContactRescue.py → ContactRestore.py

@@ -9,16 +9,18 @@
 #  Pytho vobject: http://eventable.github.io/vobject/
 
 # Version
-version=0.2
+version=0.3
 
 # 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
 
 import sqlite3
 import vobject
 import uuid
 import argparse
+import os
 
 def DEBUG(debug,msg):
     if debug is True:
@@ -26,8 +28,9 @@ 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', required=True, help="Sqlite3 Database file usually /home/{nemo,defaultuser)/.local/share/system/Contacts/qtcontacts-sqlite/contacts.db")
+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('--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))
 args = parser.parse_args()
@@ -177,7 +180,45 @@ try:
                     except AttributeError:
                         continue
 
-            # Ausgabe
+
+            if args.avatars is not None:
+                DEBUG(args.debug,"Avatar Argument given")
+                SQLAVTRCur = SQLconn.cursor()
+                
+                ## get Avatar Filelink from DB
+                for AVTRrow in SQLAVTRCur.execute('SELECT imageURL from Avatars where contactId = ' + str(contactID)):
+                    DEBUG(args.debug,"found PHOTO entry")
+    
+    
+                    if AVTRrow[0] is not None:
+                        avatarfile=os.path.split(AVTRrow[0])[1]
+
+                        # pre-checks
+                        #  - is it a file
+                        #  - is it jpg
+
+                        import mimetypes
+                        afile=args.avatars + "/" + avatarfile
+                        
+                        DEBUG(args.debug,"Avatar File: " + afile + " mimetype: " + str(mimetypes.guess_type(afile)))
+                        if os.path.isfile(afile) and mimetypes.guess_type(afile)[0] == "image/jpeg":
+                            DEBUG(args.debug,"found file " + afile)
+                            import base64
+                            # actions
+                            #  - encode base24 to variable
+                            #  - add to vcard
+                            fileopen=open(afile,'rb')
+                            bfile=base64.b64encode(fileopen.read())
+                            fileopen.close()
+                            
+                            photo = vcf.add('photo')
+                            # add param for base64
+                            photo.value = bfile
+
+                        else:
+                            print("file " + afile + " not found or no JPG")                    
+                        
+            # Output to file
             f = open(cardfile,'w')
             f.write(vcf.serialize())
             f.close()

+ 0 - 1
SQL/Abfragen.sql

@@ -1,4 +1,3 @@
 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 Addresses.contactId = 6;

+ 1 - 1
Testdata/Output/2nd_Test_*FN*_User_*LN*.vcf

@@ -1,6 +1,6 @@
 BEGIN:VCARD
 VERSION:3.0
-UID:a503ba2a-7671-4d54-a834-b1c0511e8d65
+UID:95af18d6-848d-45a6-b16c-e960e3a3093d
 FN:2nd Test *FN* User *LN*
 N:User *LN*;2nd Test *FN*;;;
 ORG:Great Copany;None

+ 1 - 1
Testdata/Output/Ludowig_Adressuser.vcf

@@ -1,6 +1,6 @@
 BEGIN:VCARD
 VERSION:3.0
-UID:62634a99-ab57-48fa-8d11-4018aa91d0f3
+UID:8498e5a7-dd19-42e8-ae38-ac7608c335f6
 ADR:;;privateParcelStreet 1;pPC;pPR;12345;pPCo
 ADR:;;POSTAL;;;;
 ADR:;;DOMESTIC;;;;

+ 0 - 0
Testdata/contacts_with-Phone-Mobile-Fax-Pager-Assistent-Addresses.db-wal → Testdata/Output/Maik_Mustermann.vcf


+ 1 - 1
Testdata/Output/Phone_Test.vcf

@@ -1,6 +1,6 @@
 BEGIN:VCARD
 VERSION:3.0
-UID:7d3d0253-7508-478a-9016-510bd9b34954
+UID:d93a45b8-92dd-4645-8d2d-9939215c7eee
 ASSISTENT:200
 CELL:600
 FAX:300

+ 1 - 1
Testdata/Output/SiSo_Emulator.vcf

@@ -1,6 +1,6 @@
 BEGIN:VCARD
 VERSION:3.0
-UID:a7dc65db-b090-48c4-9699-db0b865430b1
+UID:b3c04560-3c14-44c0-8468-b5d7d9168da8
 EMAIL:sailfish@siningsoft.de
 EMAIL:sailfishdev@siningsoft.de
 FN:SiSo Emulator

+ 1 - 1
Testdata/Output/TestUserFirstName_TestUserLastName.vcf

@@ -1,6 +1,6 @@
 BEGIN:VCARD
 VERSION:3.0
-UID:623b99fc-35da-40af-90ce-bb8fcb46c37d
+UID:a8be7385-b83f-46f9-bf17-d512d1f5228b
 CELL:01719994445
 CELL:01720004443
 FAX:040111222335

二进制
Testdata/avatars/ImperialStarTrooper_facepalm-20210810_205726.jpg


二进制
Testdata/contacts_with-Maik-Mustermann.db


二进制
Testdata/contacts_with-Maik-Mustermann_Photo.db


+ 0 - 0
Testdata/contacts_with-Phone-Mobile-Fax-Pager-Assistent-Addresses.db-shm → Testdata/contacts_with-Maik-Mustermann_Photo.db-shm


+ 0 - 0
Testdata/contacts_with-Maik-Mustermann_Photo.db-wal