Skip to content

Instantly share code, notes, and snippets.

@D3MZ
Created October 25, 2012 02:18
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 D3MZ/3950089 to your computer and use it in GitHub Desktop.
Save D3MZ/3950089 to your computer and use it in GitHub Desktop.
Import Extreme Startups Contacts, Export to Vcards
# download this gist, and cd into folder.
$ sudo gem i vpim #Installs vpim
$ ruby make_vcard.rb ~/Downloads/Extreme\ Startups\ Contact\ List\ \%282\%29\ -\ Contact\ List.csv #Yours will be slightly different. ruby make_vcard.rb file_path
require 'csv'
require 'pp'
require 'vpim/vcard'
#file_name = "Extreme Startups Contact List %282%29 - Contact List.csv"
#path = ENV['HOME']+"/Downloads/" + file_name
#csv_data = CSV.read(path)
file_path = ARGV[0]
if file_path.empty?
puts "you must specify the file path."
else
csv_data = CSV.read(file_path)
headers = csv_data.shift.map {|i| i.to_s }
string_data = csv_data.map {|row| row.map {|cell| cell.to_s } }
array_of_hashes = string_data.map {|row| Hash[*headers.zip(row).flatten] }
people = array_of_hashes.delete_if {|h| h["Cell"].empty? }
people.each do |person|
card = Vpim::Vcard::Maker.make2 do |maker|
maker.add_name do |name|
name.given = person["First Name"]
name.family = person["Last Name"]
end
maker.nickname = "Extreme Startups | #{person["Company"]}" #for indexing on phone.
maker.add_tel(person["Cell"]) { |t| t.location = 'cell'; t.preferred = true }
maker.add_email(person["Work Email"]) { |e| e.location = 'work' }
end
path = ENV['HOME']+"/#{person["Company"]}_#{person["First Name"]}_#{person["Last Name"]}.vcf"
File.open(path, 'w') {|f| f.write(card) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment