russ (owner)

Revisions

gist: 134670 Download_button fork
public
Public Clone URL: git://gist.github.com/134670.git
Ruby
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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