Created
January 4, 2019 16:33
-
-
Save cdinu/c3e9dba785645343b6ed73beb69f9491 to your computer and use it in GitHub Desktop.
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
## 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