refine parsing with pythhonvCard4
This commit is contained in:
parent
95a5b7d35c
commit
9151351ac9
1 changed files with 26 additions and 12 deletions
|
|
@ -1,19 +1,33 @@
|
||||||
import pickle
|
import pickle
|
||||||
from pythonvCard4.vcard import Contact
|
from pythonvCard4.vcard import Contact
|
||||||
|
import base64
|
||||||
|
import os
|
||||||
|
|
||||||
input = open("contacts.vcf", 'r').readlines()
|
file = open("contacts.vcf", 'r').readlines()
|
||||||
output = open("processed.vcf", 'w')
|
|
||||||
|
|
||||||
for line in input:
|
cards = []
|
||||||
|
|
||||||
if "TEL" in line:
|
current_card = ""
|
||||||
line = line.replace('-', '')
|
for line in file:
|
||||||
if ":06" in line: line = line.replace(":06", ":+336")
|
current_card += line
|
||||||
if ":07" in line: line = line.replace(":07", ":+337")
|
if "END:VCARD" in line:
|
||||||
if ":00" in line: line = line.replace(":00", ":+")
|
contact = Contact.from_vcard(current_card)
|
||||||
if ":09" in line: line = line.replace(":09", ":+339")
|
if "PHOTO" in contact.custom and len(contact.custom["PHOTO"]) > 1:
|
||||||
if ":01" in line: line = line.replace(":01", ":+331")
|
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])))
|
||||||
|
|
||||||
print(line)
|
cards.append(contact)
|
||||||
|
current_card = ""
|
||||||
|
continue
|
||||||
|
|
||||||
output.write(line)
|
|
||||||
|
# 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))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue