Created
December 5, 2008 20:56
-
-
Save rmm5t/32507 to your computer and use it in GitHub Desktop.
vCards -> Asterisk commands for improved caller id
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 | |
# 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