Last active
November 2, 2022 10:40
-
-
Save daom89/5a3461652d26a9c084aab8202354e36d to your computer and use it in GitHub Desktop.
vCard vcf Files export to csv Google contacts Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, vobject, csv | |
from os import walk | |
titles = [ "Name" | |
,"Given Name" | |
,"Additional Name" | |
,"Family Name" | |
,"Yomi Name" | |
,"Given Name Yomi" | |
,"Additional Name Yomi" | |
,"Family Name Yomi" | |
,"Name Prefix" | |
,"Name Suffix" | |
,"Initials" | |
,"Nickname" | |
,"Short Name" | |
,"Maiden Name" | |
,"Birthday" | |
,"Gender" | |
,"Location" | |
,"Billing Information" | |
,"Directory Server" | |
,"Mileage" | |
,"Occupation" | |
,"Hobby" | |
,"Sensitivity" | |
,"Priority" | |
,"Subject" | |
,"Notes" | |
,"Language" | |
,"Photo" | |
,"Group Membership" | |
,"Phone 1 - Type" | |
,"Phone 1 - Value"] | |
contacts = [] | |
for (dirpath, dirnames, filenames) in walk(os.getcwd()): | |
for filename in filenames: | |
if not filename.endswith( ('.py', '.csv')): | |
with open(filename) as file: | |
vcard = vobject.readOne(file) | |
contact = [ | |
str(vcard.n.value).strip(), | |
str(vcard.n.value).strip()] | |
contact.extend([""] * 27) | |
#contact.extend(["Mobile",str(vcard.tel.value).strip().replace("038", "601")]) #Change indicative | |
contact.extend(["Mobile",str(vcard.tel.value).strip()) | |
contacts.append(contact) | |
with open('Contactos.csv', 'w', newline='') as f: | |
# using csv.writer method from CSV package | |
write = csv.writer(f) | |
write.writerow(titles) | |
write.writerows(contacts) | |
f.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy the .py file into the vcf folder files and run the script