Skip to content

Instantly share code, notes, and snippets.

@c7h
Created April 16, 2013 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c7h/5396518 to your computer and use it in GitHub Desktop.
Save c7h/5396518 to your computer and use it in GitHub Desktop.
CSV to VCARD
#!/usr/bin/python
import sys
import csv
def convert(filename):
reader = csv.reader(open(filename, 'rb'))
for row in reader:
lastname = row[0]
firstname = row[1]
mail = row[2]
tel = row[3]
print 'BEGIN:VCARD'
print 'VERSION:2.1'
print 'N:%s;%s' % (lastname, firstname)
print 'FN:%s %s' % (firstname, lastname)
print 'TEL;HOME;VOICE:' + tel
print 'EMAIL;PREF;INTERNET:'+mail
print 'END:VCARD'
if __name__ == "__main__":
args = sys.argv
if len(args) != 2:
print "Usage:"
print args[0] + " filename"
else:
convert(args[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment