|
|
@@ -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()
|