refine input/output
This commit is contained in:
parent
ef47ee5773
commit
98fb0b13f4
1 changed files with 15 additions and 19 deletions
|
|
@ -1,33 +1,29 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import base64
|
||||||
import pickle
|
import pickle
|
||||||
from pythonvCard4.vcard import Contact
|
from pythonvCard4.vcard import Contact
|
||||||
import base64
|
|
||||||
import os
|
|
||||||
|
|
||||||
file = open("contacts.vcf", 'r').readlines()
|
input_file = open(sys.argv[1], 'r').readlines()
|
||||||
|
|
||||||
cards = []
|
cards = []
|
||||||
|
|
||||||
current_card = ""
|
current_card = ""
|
||||||
for line in 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 "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("photo/" + contact.fn, exist_ok=True)
|
||||||
for image in range(len(contact.custom["PHOTO"])):
|
# for image in range(len(contact.custom["PHOTO"])):
|
||||||
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])))
|
||||||
|
|
||||||
cards.append(contact)
|
cards.append(contact)
|
||||||
current_card = ""
|
current_card = ""
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
output = open('output.vcf', 'w')
|
||||||
# contact = Contact.from_vcard(cards[156])
|
for card in cards:
|
||||||
# print(contact.custom["PHOTO"])
|
vcf_text = card.to_vcard()
|
||||||
|
print(vcf_text)
|
||||||
# vcf_text = contact.to_vcard()
|
output.write(vcf_text)
|
||||||
# print(vcf_text)
|
|
||||||
# open('test.vcf', 'w').write(vcf_text)
|
|
||||||
|
|
||||||
print(len(cards))
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue