Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
got shebang put on right
Browse files Browse the repository at this point in the history
  • Loading branch information
rschultheis committed Sep 10, 2011
1 parent cbd5929 commit 4953a7c
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 387 deletions.
115 changes: 59 additions & 56 deletions bin/pa_auction_bot.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,56 +1,59 @@
require 'optparse'
#require 'rubygems'


#Deal with the cmd line
def parse_cmd_line
options = {
:hooks_file => 'bots/csv_logger.rb',
:site => 'QUIBIDS',
}

optparse = OptionParser.new do |opts|
opts.banner = %Q|
Penny Auction Observer
example: ruby -I lib bin/pa_auction_but.rb bots/csv_logger.rb
|

opts.on("-b", "--bot-file=FILE_NAME",
"specify the bot file to execute, default is '#{options[:hooks_file]}'") { |filename| options[:hooks_file] = filename}

opts.on("-a", "--auction-id=AUCTION_ID",
"the auction id") { |id| options[:auction_id] = id }

opts.on("-s", "--site=SITE",
"Specify the site to use, default is '#{options[:site]}'") { |site| options[:site] = site}


end
optparse.parse!
options
end
options = parse_cmd_line



require 'pa_site'
require 'pa_observer'

#setup the object
auction_id = options[:auction_id]
load options[:hooks_file]
pa_site = QB_Site.new options[:site].upcase
pa_site.start auction_id



auction_observer = QB_Observer.new pa_site


auction_observer.hooks[:on_new_bids] = OnNewBids
auction_observer.hooks[:on_new_auction] = OnNewAuction
auction_observer.hooks[:on_auction_end] = OnAuctionEnd
auction_observer.hooks[:on_timer_threshold] = OnTimerThreshold

auction_observer.observe_auction
#!/usr/bin/env ruby
require 'optparse'
#require 'rubygems'


#Deal with the cmd line
def parse_cmd_line
options = {
:hooks_file => 'bots/csv_logger.rb',
:site => 'QUIBIDS',
}

optparse = OptionParser.new do |opts|
opts.banner = %Q|
Penny Auction Observer
example: ruby -I lib bin/pa_auction_but.rb bots/csv_logger.rb
|

opts.on("-b", "--bot-file=FILE_NAME",
"specify the bot file to execute, default is '#{options[:hooks_file]}'") { |filename| options[:hooks_file] = filename}

opts.on("-a", "--auction-id=AUCTION_ID",
"the auction id") { |id| options[:auction_id] = id }

opts.on("-s", "--site=SITE",
"Specify the site to use, default is '#{options[:site]}'") { |site| options[:site] = site}


end
optparse.parse!
options
end
options = parse_cmd_line

## Take care of loading the libraries... not sure if this is the best way but it works...
BASE_DIR = File.dirname(File.dirname($0))
LIB_DIR = File.join(BASE_DIR, 'lib')
BOTS_DIR = File.join(BASE_DIR, 'bots')
$: << LIB_DIR << BOTS_DIR

require 'pa_site'
require 'pa_observer'

#setup the auction observerobject object
auction_id = options[:auction_id]
load options[:hooks_file]

pa_site = QB_Site.new options[:site].upcase
pa_site.start auction_id

auction_observer = QB_Observer.new pa_site

auction_observer.hooks[:on_new_bids] = OnNewBids
auction_observer.hooks[:on_new_auction] = OnNewAuction
auction_observer.hooks[:on_auction_end] = OnAuctionEnd
auction_observer.hooks[:on_timer_threshold] = OnTimerThreshold

auction_observer.observe_auction
76 changes: 38 additions & 38 deletions bots/basic_watcher.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
## Logs a QuiBids Auction to STDOUT
#

## NEW BIDS
#data
num_bids = 0
last_amt = -1.0

## AUCTION HOOKS
OnNewAuction = lambda {|auction_name|
last_amt = -1.0
num_bids = 0
puts "Now watching new auction: #{auction_name}"
}

OnAuctionEnd = lambda {|auction_name|
puts "Done watching auction: #{auction_name}"
}


OnNewBids = lambda {|new_bids|
new_bids.each do |bid|
num_bids += 1
puts "NEW BID: '#{bid[:bidder]}' : '#{bid[:amt]}' : '#{bid[:type]}' : #{bid[:last_secs]} : #{last_amt}"
end
last_amt = new_bids.last[:amt] if new_bids.count > 0
puts "Processed #{new_bids.count} new bids"
}



## TIMER THRESHOLD
num_hits = 0
OnTimerThreshold = lambda {|secs, browser|
#browser.bid
num_hits += 1
puts "TIMER THRESHOLD HIT: #{num_hits} so far"
}
## Logs a QuiBids Auction to STDOUT
#

## NEW BIDS
#data
num_bids = 0
last_amt = -1.0

## AUCTION HOOKS
OnNewAuction = lambda {|auction_name|
last_amt = -1.0
num_bids = 0
puts "Now watching new auction: #{auction_name}"
}

OnAuctionEnd = lambda {|auction_name|
puts "Done watching auction: #{auction_name}"
}


OnNewBids = lambda {|new_bids|
new_bids.each do |bid|
num_bids += 1
puts "NEW BID: '#{bid[:bidder]}' : '#{bid[:amt]}' : '#{bid[:type]}' : #{bid[:last_secs]} : #{last_amt}"
end
last_amt = new_bids.last[:amt] if new_bids.count > 0
puts "Processed #{new_bids.count} new bids"
}



## TIMER THRESHOLD
num_hits = 0
OnTimerThreshold = lambda {|secs, browser|
#browser.bid
num_hits += 1
puts "TIMER THRESHOLD HIT: #{num_hits} so far"
}
96 changes: 48 additions & 48 deletions bots/bidder.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
## Logs a QuiBids Auction to CSV
#

require 'bidder_model'

## NEW BIDS
#data
num_bids = 0
num_skips = 0
last_amt = -1.0


## AUCTION HOOKS
OnNewAuction = lambda {|auction_name|

@model = QB_Model.new
puts "Initialized '#{auction_name}'"
}

OnAuctionEnd = lambda {|auction_name|
puts "Auction End"
}


OnNewBids = lambda {|new_bids|

@model.process_new_bids new_bids


}



## TIMER THRESHOLD
num_bids = 0
OnTimerThreshold = lambda {|secs, browser|
if @model.would_bid
#browser.bid
num_bids += 1
puts "TIMER HIT: #{num_bids} so far"
print "\a"
else
num_skips += 1
puts "SKIP: #{num_skips} so far"
end
}

## Logs a QuiBids Auction to CSV
#

require 'bidder_model'

## NEW BIDS
#data
num_bids = 0
num_skips = 0
last_amt = -1.0


## AUCTION HOOKS
OnNewAuction = lambda {|auction_name|

@model = QB_Model.new
puts "Initialized '#{auction_name}'"
}

OnAuctionEnd = lambda {|auction_name|
puts "Auction End"
}


OnNewBids = lambda {|new_bids|

@model.process_new_bids new_bids


}



## TIMER THRESHOLD
num_bids = 0
OnTimerThreshold = lambda {|secs, browser|
if @model.would_bid
#browser.bid
num_bids += 1
puts "TIMER HIT: #{num_bids} so far"
print "\a"
else
num_skips += 1
puts "SKIP: #{num_skips} so far"
end
}


Loading

0 comments on commit 4953a7c

Please sign in to comment.