Skip to content

Instantly share code, notes, and snippets.

@bkbilly
Forked from rmm5t/vcard_skidoosh.rb
Created October 18, 2016 17:35
Show Gist options
  • Save bkbilly/c2b0f4adb3bbbb313c53b6e0dca43b49 to your computer and use it in GitHub Desktop.
Save bkbilly/c2b0f4adb3bbbb313c53b6e0dca43b49 to your computer and use it in GitHub Desktop.
vCards -> Asterisk commands for improved caller id
#!/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