Created
March 30, 2012 16:49
-
-
Save TimothyYe/2252784 to your computer and use it in GitHub Desktop.
A ruby script to check the stocks of BuyVM
This file contains 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
#BuyVMStock.rb | |
#Written by Timothy 2012.03.29 | |
#Run it with: ruby BuyVMStock.rb | |
require 'open-uri' | |
require 'json' | |
MailTo = "[email protected]" | |
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