Last active
January 2, 2016 09:59
-
-
Save cogwirrel/8286566 to your computer and use it in GitHub Desktop.
Check whether certain flavours of a product are in stock on monstersupplements.com, and email you if they are!
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
require "net/http" | |
require "uri" | |
require "net/smtp" | |
product = "C4 Extreme" | |
url = "http://monstersupplements.com/store/p/5548/1/Cellucor-C4-Extreme-60-servings.html" | |
flavours = ["Fruit Punch", "Orange", "Blue Raspberry", "Green Apple", "Watermelon"] | |
wantedFlavours = ["Orange", "Watermelon"] | |
emails = ["your@email.com", "another@email.com"] | |
def sendEmail(tos, subject, body) | |
tos.each do |to| | |
command = "echo \"#{body}\" | mail -s \"#{subject}\" #{to}" | |
system command | |
end | |
end | |
responseBody = Net::HTTP.get_response(URI.parse(url)).body | |
outOfStock = flavours.select do |flavour| | |
isOutOfStock = false | |
responseBody.each_line do |line| | |
isOutOfStock ||= line.include?("label") && line.include?(flavour) && line.include?("Out of Stock") | |
end | |
isOutOfStock | |
end | |
inStock = flavours - outOfStock | |
wantedInStock = inStock & wantedFlavours | |
if wantedInStock.length > 0 | |
subject = "#{product} In Stock!!" | |
body = "The flavour(s) in stock: #{wantedInStock.inspect}" | |
sendEmail(emails, subject, body) | |
puts "#{wantedInStock.inspect} in stock!!!" | |
exit 0 | |
else | |
puts "Out of stock of wanted flavours :(" | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
monster.rb
Parameters
Parameters are defined at the top as follows:
product
: Name of the product you're polling at monster supplements (can be anything, just used in the email)url
: The url of the product on Monster Supplementsflavours
: A list of all of the flavours of a product available (must be exactly as written on monster supplements page)wantedFlavours
: A list of the flavours you want to check for (must be a subset offlavours
)emails
: The email addresses to send an email to if the product is available in one or more of the wanted flavours.Requirements
Requires
mail
unix command all set up.Suggested Use
Use it to poll Monster Supplements to notify you when a certain product you're waiting for becomes available with a bash script like: