Compare commits

..

No commits in common. "01ebe8b545fadf47a5894baf6d68121c3d7f0aef" and "71a88ef1b5a49b0fef0b7e2641863e2caad50049" have entirely different histories.

3 changed files with 20 additions and 45 deletions

4
.gitignore vendored
View file

@ -1,5 +1,3 @@
*.vcf *.vcf
/vcf /vcf
/pictures /photo
/multiple_pictures
/whatsapp

View file

@ -1 +0,0 @@

View file

@ -1,55 +1,33 @@
import os
import sys
import base64
import pickle import pickle
import phonenumbers
from pythonvCard4.vcard import Contact from pythonvCard4.vcard import Contact
import base64
import os
input_file = open(sys.argv[1], 'r').readlines() file = open("contacts.vcf", 'r').readlines()
check_for_multiple_pictures = False
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 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("multiple_pictures/" + 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])))
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 = {}
clean_tel = []
for number in contact.tel:
try:
number = number["value"]
number = number.replace("-", "")
number = phonenumbers.parse(number, region="FR")
number = phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.INTERNATIONAL)
clean_tel.append({"value": number, "type": []})
except phonenumbers.phonenumberutil.NumberParseException:
continue
contact.tel = clean_tel
cards.append(contact) cards.append(contact)
current_card = "" current_card = ""
continue continue
output = open('output.vcf', 'w')
for card in cards: # contact = Contact.from_vcard(cards[156])
vcf_text = card.to_vcard() # print(contact.custom["PHOTO"])
output.write(vcf_text)
# vcf_text = contact.to_vcard()
# print(vcf_text)
# open('test.vcf', 'w').write(vcf_text)
print(len(cards))