clean duplicate pictures
This commit is contained in:
parent
a334cbeee1
commit
ad30bee143
1 changed files with 12 additions and 1 deletions
|
|
@ -9,18 +9,29 @@ check_for_multiple_pictures = False
|
||||||
|
|
||||||
cards = []
|
cards = []
|
||||||
current_card = ""
|
current_card = ""
|
||||||
|
|
||||||
for line in input_file:
|
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 check_for_multiple_pictures:
|
if check_for_multiple_pictures:
|
||||||
if "PHOTO" in contact.custom and len(contact.custom["PHOTO"]) > 1:
|
if "PHOTO" in contact.custom and len(contact.custom["PHOTO"]) > 1:
|
||||||
os.makedirs("photo/" + contact.fn, exist_ok=True)
|
os.makedirs("multiple_pictures/" + contact.fn, exist_ok=True)
|
||||||
for image in range(len(contact.custom["PHOTO"])):
|
for image in range(len(contact.custom["PHOTO"])):
|
||||||
print(contact.custom["PHOTO"][image])
|
print(contact.custom["PHOTO"][image])
|
||||||
with open("photo/" + contact.fn + "/" + str(image) + ".jpg", "wb") as f:
|
with open("photo/" + contact.fn + "/" + str(image) + ".jpg", "wb") as f:
|
||||||
f.write(base64.decodebytes(str.encode(contact.custom["PHOTO"][image])))
|
f.write(base64.decodebytes(str.encode(contact.custom["PHOTO"][image])))
|
||||||
|
|
||||||
|
if "PHOTO" in contact.custom:
|
||||||
|
os.makedirs("pictures/" + contact.fn, exist_ok=True)
|
||||||
|
with open("pictures/" + contact.fn + "/profile.jpg", "wb") as f:
|
||||||
|
f.write(base64.decodebytes(str.encode(contact.custom["PHOTO"][0])))
|
||||||
|
contact.photo_path = "pictures/" + contact.fn + "/profile.jpg"
|
||||||
|
contact.custom = {}
|
||||||
|
|
||||||
cards.append(contact)
|
cards.append(contact)
|
||||||
current_card = ""
|
current_card = ""
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue