Skip to content

Instantly share code, notes, and snippets.

@cdinu
Created January 4, 2019 16:33
Show Gist options
  • Save cdinu/c3e9dba785645343b6ed73beb69f9491 to your computer and use it in GitHub Desktop.
Save cdinu/c3e9dba785645343b6ed73beb69f9491 to your computer and use it in GitHub Desktop.
## requires a `pip install vobject`
import vobject
import io
import csv
reader = io.open("contacts.vcf", "r", encoding="utf-8")
output_file = open('contacts.csv', mode='w')
writer = csv.writer(output_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(["username", "name.first", "name.last"])
i = 1
for vcard in vobject.readComponents(reader):
try:
writer.writerow([vcard.email.value, vcard.n.value.given, vcard.n.value.family])
print(i, vcard.email.value)
i = i+1
except AttributeError:
pass
reader.close()
output_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment