Created
December 20, 2013 20:55
-
-
Save eurica/8061401 to your computer and use it in GitHub Desktop.
Ruby script to check numbers against the Twilio Price list.
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
require 'csv' | |
#Parse the CSV that Twilio provides https://www.twilio.com/resources/rates/international-rates.csv | |
numbers = [] | |
CSV.foreach('international-rates.csv', :headers => true) do |row| | |
starts = row[2].split(",") | |
starts.each do |p| | |
numbers.push([p.strip, p.strip.length, row[1], row[0]]) | |
end | |
end | |
#Sort the list in descending length order | |
numbers.sort! { |x, y| -x[1] <=> -y[1] } | |
CSV.open("rates-in-length-order.csv", "w") do |csv| | |
numbers.each do |p| | |
csv << p | |
end | |
end | |
# Loop through our numbers, and find the longest Twilio code that matches | |
# This searches the list provided by Twilio for *every* number, it's horribly inefficient! | |
CSV.open("numbers-with-costs.csv", "w") do |csv| | |
csv << ["Number", "Twilio Start", "Cost", "Country"] | |
CSV.foreach('our-numbers.csv', :headers => true) do |row| | |
number = "#{row[0]}" | |
numbers.each do |n| | |
if number.start_with? n[0] | |
csv << [number, n[0], n[2], n[3]] | |
puts "#{number} costs #{n[2]}" | |
break | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment