Skip to content

Instantly share code, notes, and snippets.

@russ
Created June 23, 2009 16:47
Show Gist options
  • Save russ/134670 to your computer and use it in GitHub Desktop.
Save russ/134670 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'optparse'
class BagOfCrap
def initialize(args)
@url = "http://www.woot.com"
@standard_sleep = 15
@sold_out_sleep = 3
@break_loop = false
trap('INT') { @break_loop = true }
trap('TERM') { @break_loop = true }
@options = {}
opts = OptionParser.new
opts.on('-T', '--talk') { @options[:talk] = true }
opts.on('-V', '--verbose') { @options[:verbose] = true }
opts.parse!(args) rescue return false
end
def run
while(true) do
break if @break_loop
doc = Nokogiri::HTML(open(@url).read)
current_item = doc.at('h2').inner_html
last_item ||= nil
if current_item != last_item
puts "#{Time.now.strftime('%T')} - #{current_item}" if @options[:verbose]
# system "say \"#{current_item}\"" if @options[:talk]
end
if doc.at('h2').to_s =~ /Random Crap/
system "epiphany http://www.woot.com"
break
elsif doc.css('a.soldOut').length > 0
sleep @sold_out_sleep
else
sleep @standard_sleep
end
last_item = current_item
break if @break_loop
end
end
end
BagOfCrap.new(ARGV).run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment