import os import sys import base64 import pickle from pythonvCard4.vcard import Contact input_file = open(sys.argv[1], 'r').readlines() check_for_multiple_pictures = False cards = [] current_card = "" for line in input_file: current_card += line if "END:VCARD" in line: contact = Contact.from_vcard(current_card) if check_for_multiple_pictures: if "PHOTO" in contact.custom and len(contact.custom["PHOTO"]) > 1: os.makedirs("photo/" + contact.fn, exist_ok=True) for image in range(len(contact.custom["PHOTO"])): print(contact.custom["PHOTO"][image]) with open("photo/" + contact.fn + "/" + str(image) + ".jpg", "wb") as f: f.write(base64.decodebytes(str.encode(contact.custom["PHOTO"][image]))) cards.append(contact) current_card = "" continue output = open('output.vcf', 'w') for card in cards: vcf_text = card.to_vcard() output.write(vcf_text)