Skip to content

Instantly share code, notes, and snippets.

@daom89
Last active November 2, 2022 10:40
Show Gist options
  • Save daom89/5a3461652d26a9c084aab8202354e36d to your computer and use it in GitHub Desktop.
Save daom89/5a3461652d26a9c084aab8202354e36d to your computer and use it in GitHub Desktop.
vCard vcf Files export to csv Google contacts Python
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
@daom89
Copy link
Author

daom89 commented Nov 2, 2022

Copy the .py file into the vcf folder files and run the script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment