Skip to content

Instantly share code, notes, and snippets.

@musha68k
Created February 12, 2016 00:22
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 musha68k/748ea4c8d92944c84a0c to your computer and use it in GitHub Desktop.
Save musha68k/748ea4c8d92944c84a0c to your computer and use it in GitHub Desktop.
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