Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Converts multiple single person 2.1 vcard files from a Nokia dumb-phone export (".vcf") into one iCloud web contacts importable vcards collection file
#!/usr/bin/env ruby
require 'vpim'
require 'vcardio'
files = Dir.glob "*.vcf"
vcards = files.map do |f|
vc_old = Vpim::Vcard.decode(File.read(f))[0]
# proper vcard 4.0 wasn't accepted by the iCLoud web-interface
# so we need to set both the FN as well as the N field again
vc_new = VCardio::VCard.new('3.0') do
vc_old.fields.each do |field|
n field.value if field.name == "N"
fn field.value if field.name == "N"
tel field.value if field.name == "TEL"
end
end
vc_new.to_s
end
export_file = File.new("export.vcf", "w")
export_file.write vcards.join("\n\n") + "\n"
export_file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment