Getting the Nintendo Wii with Ruby, Almost
December 29th, 2006
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!
on December 29th, 2006 at 12:45 PM I'm just stoked you used ruby :)
on December 29th, 2006 at 06:59 PM 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...
on December 29th, 2006 at 07:23 PM 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.
on December 29th, 2006 at 10:46 PM Ruby FTW!, almost :''( anywho... where did you get that spiffy syntax coloring?
on December 29th, 2006 at 11:00 PM Why don't you use while? :P n = 0 while true ... puts "#{n+=1}:\t#{found}" ... end
on December 29th, 2006 at 11:01 PM I describe the syntax highlighter here.
on December 29th, 2006 at 11:34 PM The trouble with a while loop is that if I were to die it would never stop.
on December 30th, 2006 at 04:25 AM Cool piece of code
on December 30th, 2006 at 05:33 AM err.. then you can try.. while me.alive? ... end I think it will work well :P