Skip to content

Instantly share code, notes, and snippets.

@rmm5t
Created December 5, 2008 20:56
Show Gist options
  • Save rmm5t/32507 to your computer and use it in GitHub Desktop.
Save rmm5t/32507 to your computer and use it in GitHub Desktop.
vCards -> Asterisk commands for improved caller id
#!/usr/bin/env ruby
# Example Usage:
# vcard2asterisk *.vcf
# vcard2asterisk http://getvcard.com/dogetvcard.asp?UID=LD7U7mM
require 'rubygems'
require 'vpim/vcard'
def format_phone_number(phone)
number = phone.to_s.gsub(/\D/, "")
(number =~ /^1/) ? number[0...11] : "1#{number[0...10]}"
end
ARGV.each do |file|
cards = Vpim::Vcard.decode(open(file))
cards.each do |card|
name = card.name.fullname
card.telephones.each do |phone|
number = format_phone_number(phone)
location = phone.location.first || phone.nonstandard.first || "Unknown"
puts %(asterisk -rx 'database put cidname #{number} "#{name} [#{location[0].chr.upcase}]"')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment