add possible check for multiple pictures
This commit is contained in:
parent
98fb0b13f4
commit
3f3b3d948e
1 changed files with 8 additions and 6 deletions
|
|
@ -5,6 +5,7 @@ import pickle
|
||||||
from pythonvCard4.vcard import Contact
|
from pythonvCard4.vcard import Contact
|
||||||
|
|
||||||
input_file = open(sys.argv[1], 'r').readlines()
|
input_file = open(sys.argv[1], 'r').readlines()
|
||||||
|
check_for_multiple_pictures = False
|
||||||
|
|
||||||
cards = []
|
cards = []
|
||||||
current_card = ""
|
current_card = ""
|
||||||
|
|
@ -12,11 +13,13 @@ for line in input_file:
|
||||||
current_card += line
|
current_card += line
|
||||||
if "END:VCARD" in line:
|
if "END:VCARD" in line:
|
||||||
contact = Contact.from_vcard(current_card)
|
contact = Contact.from_vcard(current_card)
|
||||||
# if "PHOTO" in contact.custom and len(contact.custom["PHOTO"]) > 1:
|
if check_for_multiple_pictures:
|
||||||
# os.makedirs("photo/" + contact.fn, exist_ok=True)
|
if "PHOTO" in contact.custom and len(contact.custom["PHOTO"]) > 1:
|
||||||
# for image in range(len(contact.custom["PHOTO"])):
|
os.makedirs("photo/" + contact.fn, exist_ok=True)
|
||||||
# with open("photo/" + contact.fn + "/" + str(image) + ".jpg", "wb") as f:
|
for image in range(len(contact.custom["PHOTO"])):
|
||||||
# f.write(base64.decodebytes(str.encode(contact.custom["PHOTO"][image])))
|
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)
|
cards.append(contact)
|
||||||
current_card = ""
|
current_card = ""
|
||||||
|
|
@ -25,5 +28,4 @@ for line in input_file:
|
||||||
output = open('output.vcf', 'w')
|
output = open('output.vcf', 'w')
|
||||||
for card in cards:
|
for card in cards:
|
||||||
vcf_text = card.to_vcard()
|
vcf_text = card.to_vcard()
|
||||||
print(vcf_text)
|
|
||||||
output.write(vcf_text)
|
output.write(vcf_text)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue