2025-05-07 09:01:40 +02:00
|
|
|
import pickle
|
|
|
|
|
from pythonvCard4.vcard import Contact
|
2025-05-07 10:00:29 +02:00
|
|
|
import base64
|
|
|
|
|
import os
|
2025-05-07 09:01:40 +02:00
|
|
|
|
2025-05-07 10:00:29 +02:00
|
|
|
file = open("contacts.vcf", 'r').readlines()
|
2025-05-07 09:01:40 +02:00
|
|
|
|
2025-05-07 10:00:29 +02:00
|
|
|
cards = []
|
2025-05-07 09:01:40 +02:00
|
|
|
|
2025-05-07 10:00:29 +02:00
|
|
|
current_card = ""
|
|
|
|
|
for line in file:
|
|
|
|
|
current_card += line
|
|
|
|
|
if "END:VCARD" in line:
|
|
|
|
|
contact = Contact.from_vcard(current_card)
|
|
|
|
|
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"])):
|
|
|
|
|
with open("photo/" + contact.fn + "/" + str(image) + ".jpg", "wb") as f:
|
|
|
|
|
f.write(base64.decodebytes(str.encode(contact.custom["PHOTO"][image])))
|
2025-05-07 09:01:40 +02:00
|
|
|
|
2025-05-07 10:00:29 +02:00
|
|
|
cards.append(contact)
|
|
|
|
|
current_card = ""
|
|
|
|
|
continue
|
2025-05-07 09:01:40 +02:00
|
|
|
|
2025-05-07 10:00:29 +02:00
|
|
|
|
|
|
|
|
# contact = Contact.from_vcard(cards[156])
|
|
|
|
|
# print(contact.custom["PHOTO"])
|
|
|
|
|
|
|
|
|
|
# vcf_text = contact.to_vcard()
|
|
|
|
|
# print(vcf_text)
|
|
|
|
|
# open('test.vcf', 'w').write(vcf_text)
|
|
|
|
|
|
|
|
|
|
print(len(cards))
|