Why is the Wii so hard to find? It’s not like it’s a Harley Davidson. It will be worth half it’s purchase price in a year. Tara told me the Wii would be on sale at Amazon for $249.99 and clicking refresh for several hours on a Friday-off is not my idea of a good time. Ruby to the rescue.


require 'uri'
require 'net/http'

uri = "http://www.amazon.com/Nintendo-Wii-Family-Bundle/dp/B0009VXBAQ/ref=tag_tdp_pl/002-9439078-6124858" 
look_for = /\$2[0-5][0-9]/

for n in 1..100000
  req = Net::HTTP.get_response(URI.parse(uri))
  found = (req.body[0..70000] =~ look_for)
  puts "#{n}:\t#{found}" 
  `./sound` if found
  sleep 4
end

The script checked Amazon.com for something that looked like a price every 4 seconds. When the beeping started Tara hit refresh in her browser and nothing was there, most likely due to a caching issue. By the time I got my browser up and pointed to the Wii we were on the third beep (12 seconds). Sure enough it indicated it was for sale but when I clicked Add to Cart I got a message informing me that Amazon had sold out. I conclude that they sold out in WAY less than 20 seconds. My guess it that it was closer to 12-16 seconds but I can’t prove that.

I think I need a mulit-threaded version that checks 50 times per second and adds to cart automatically. That may be the only way to do it. Someone let me know if they write one.

This is just wrong. No more Mr. nice (4 second) guy!

9 Responses Follows

  1. Chuck says
    I'm just stoked you used ruby :)
  2. Joe says
    https://addons.mozilla.org/firefox/920/ check it out... you'll prolly have to write you're on PUC, but it's not too hard...
  3. Sam says
    The PUC for FF looks interesting. I actually tried an MD5 hash of the page to see when it changed but it was different every time so I instead looked for an approxmiate price in the first 70,000 chars.
  4. Andrew says
    Ruby FTW!, almost :''( anywho... where did you get that spiffy syntax coloring?
  5. CFC says
    Why don't you use while? :P n = 0 while true ... puts "#{n+=1}:\t#{found}" ... end
  6. Sam says
    I describe the syntax highlighter here.
  7. Sam says
    The trouble with a while loop is that if I were to die it would never stop.
  8. Justin says
    Cool piece of code
  9. CFC says
    err.. then you can try.. while me.alive? ... end I think it will work well :P

Your Response