Created
February 12, 2016 00:22
-
-
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
This file contains 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
#!/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