Compare commits
8 commits
71a88ef1b5
...
01ebe8b545
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01ebe8b545 | ||
|
|
55c2e0bfd9 | ||
|
|
ad30bee143 | ||
|
|
a334cbeee1 | ||
|
|
3f3b3d948e | ||
|
|
98fb0b13f4 | ||
|
|
ef47ee5773 | ||
|
|
27aa4a4c1a |
3 changed files with 46 additions and 21 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,3 +1,5 @@
|
||||||
*.vcf
|
*.vcf
|
||||||
/vcf
|
/vcf
|
||||||
/photo
|
/pictures
|
||||||
|
/multiple_pictures
|
||||||
|
/whatsapp
|
||||||
|
|
|
||||||
1
csv_to_vcf.py
Normal file
1
csv_to_vcf.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -1,33 +1,55 @@
|
||||||
import pickle
|
|
||||||
from pythonvCard4.vcard import Contact
|
|
||||||
import base64
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import base64
|
||||||
|
import pickle
|
||||||
|
import phonenumbers
|
||||||
|
from pythonvCard4.vcard import Contact
|
||||||
|
|
||||||
file = open("contacts.vcf", 'r').readlines()
|
input_file = open(sys.argv[1], '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 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])
|
||||||
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 = {}
|
||||||
|
|
||||||
|
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')
|
||||||
# contact = Contact.from_vcard(cards[156])
|
for card in cards:
|
||||||
# print(contact.custom["PHOTO"])
|
vcf_text = card.to_vcard()
|
||||||
|
output.write(vcf_text)
|
||||||
# vcf_text = contact.to_vcard()
|
|
||||||
# print(vcf_text)
|
|
||||||
# open('test.vcf', 'w').write(vcf_text)
|
|
||||||
|
|
||||||
print(len(cards))
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue