Skip to content

Instantly share code, notes, and snippets.

@tisyang
Last active August 29, 2015 14:02
Show Gist options
  • Save tisyang/bd9130de9e951c935bd1 to your computer and use it in GitHub Desktop.
Save tisyang/bd9130de9e951c935bd1 to your computer and use it in GitHub Desktop.
contacts file csv to vcf (vcards)
fmt = "BEGIN:VCARD\nVERSION:2.1\nFN:{name}\nTEL;CELL;VOICE:{phone}\nEND:VCARD"
File.open("222.csv") do |inn|
File.open("222.vcf", "w") do |out|
while line = inn.gets do
line = line.chomp
content = line.split(",")
name = content[0]
phone = content[1]
res = fmt.sub("{name}", name).sub("{phone}", phone)
out.write(res)
out.write("\n")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment