-
-
Save bkbilly/c2b0f4adb3bbbb313c53b6e0dca43b49 to your computer and use it in GitHub Desktop.
vCards -> Asterisk commands for improved caller id
This file contains hidden or 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 | |
# usage: ruby vcard_skidoosh.rb vcard.vcf | |
# outputs a bunch of asterisk commands to stdout. | |
# taste it. | |
# Tested for VCARD version 2.1 & 3.0 | |
ARGV.collect{ |f| open(f).readlines }.flatten.each do |line| | |
if line =~ /^N:(.*)$/ | |
$name = $1.chomp | |
$name = $name.gsub!(';',' ') | |
$name = $name.scan(/\S+/) | |
elsif line =~ /^TEL;([A-Z]).*:(.+)$/ or line =~ /TEL:(.+)$/ | |
$line = line.gsub!(' ','') | |
$line = line.gsub!('-','') | |
$line = line.gsub!('(','') | |
$line = line.gsub!(')','') | |
$line = line.gsub!('+30','') | |
formatted_number = line.scan(/\d\d+/).first | |
puts %(asterisk -rx 'database put cidname #{formatted_number} "#{$name[1]} #{$name[0]}"') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment