Skip to content

Instantly share code, notes, and snippets.

@TimothyYe
Created March 30, 2012 16:49
Show Gist options
  • Save TimothyYe/2252784 to your computer and use it in GitHub Desktop.
Save TimothyYe/2252784 to your computer and use it in GitHub Desktop.
A ruby script to check the stocks of BuyVM
#BuyVMStock.rb
#Written by Timothy 2012.03.29
#Run it with: ruby BuyVMStock.rb
require 'open-uri'
require 'json'
MailTo = "YourMailAddress@gmail.com"
def SendMailNotify(content)
pipe = IO.popen("/usr/sbin/sendmail -t -v", "w")
pipe.puts "To:" + MailTo + "\n"
pipe.puts "From:BuyVM\n"
pipe.puts "Subject: BuyVM has stock now!"
pipe.puts "BuyVM has stock now! \n" + content
pipe.close_write
end
content = JSON.parse(open("http://www.doesbuyvmhavestock.com/automation.json").read)
emailContent = ''
content.each { |obj
if obj['qty'] > 0
emailContent.concat(obj['name'] + " has " )
emailContent.concat(obj['qty'].to_s() + " \n")
end
}
SendMailNotify(emailContent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment