Skip to content

Instantly share code, notes, and snippets.

@zaingz
Last active August 4, 2017 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaingz/6ce124582c23dd501840e7f9f07f7949 to your computer and use it in GitHub Desktop.
Save zaingz/6ce124582c23dd501840e7f9f07f7949 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'csv'
require "pathname"
require "http"
data = []
#this is a comment
path = Pathname.new("Message.csv")
puts path.to_s
csv_text = File.read(path)
csv = CSV.parse(csv_text, :headers => true)
csv.each do |row|
data << {mob: row[0], name: row[1], account: row[2]}
end
path = Pathname.new("body.txt")
text = File.read(path)
puts "How many SMS you want to send in a minute"
sms_pm = gets.chomp.to_i
data.each_slice(sms_pm) do |slice|
slice.each do |row|
msg = %(
Dear #{row[:name]},
Account # #{row[:account]}
#{text}
)
Thread.new do
h = HTTP.post("https://api.zipwhip.com/messaging/send",
form: {session: "25655890-fa2e-4c0a-a60c-44ae477625be:343254802", to: "1#{row[:mob]}", body: msg} )
puts "Sms sent to #{row[:mob]}, status: #{eval(h.body.to_s)[:success]}"
end
end
sleep(1*60)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment