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

Commit

Permalink
added login, a bunch of minor tweaks and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rschultheis committed Sep 10, 2011
1 parent 4953a7c commit a69a962
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
10 changes: 10 additions & 0 deletions bin/pa_auction_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def parse_cmd_line
options = {
:hooks_file => 'bots/csv_logger.rb',
:site => 'QUIBIDS',
:login => false,
}

optparse = OptionParser.new do |opts|
Expand All @@ -26,6 +27,13 @@ def parse_cmd_line
opts.on("-s", "--site=SITE",
"Specify the site to use, default is '#{options[:site]}'") { |site| options[:site] = site}

opts.on("-l", "--login=username:password",
"Specify username and password to login with, otherwise no username or password will be used") { |str|

(options[:username], options[:password]) = str.match(/^(.+):(.+)$/)[1,2]

options[:login] = true
}

end
optparse.parse!
Expand All @@ -49,6 +57,8 @@ def parse_cmd_line
pa_site = QB_Site.new options[:site].upcase
pa_site.start auction_id

pa_site.login(options[:username], options[:password]) if options[:login]

auction_observer = QB_Observer.new pa_site

auction_observer.hooks[:on_new_bids] = OnNewBids
Expand Down
6 changes: 3 additions & 3 deletions bots/bidder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
num_bids = 0
OnTimerThreshold = lambda {|secs, browser|
if @model.would_bid
#browser.bid
browser.bid
num_bids += 1
puts "TIMER HIT: #{num_bids} so far"
puts "MODEL SAID TO BID: #{num_bids} so far"
print "\a"
else
num_skips += 1
puts "SKIP: #{num_skips} so far"
puts "MODEL SAID TO SKIP BID: #{num_skips} so far"
end
}

Expand Down
17 changes: 9 additions & 8 deletions bots/bidder_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ def process_new_bids new_bids
end

@num_bids += 1
puts "NEW BID #{@num_bids}\t #{bid[:bidder]}\t #{bid[:amt]}\t #{bid[:type]}\t #{bid[:last_secs]}\t:: #{@bidders[bid[:bidder]][:count]} so far"
#puts "NEW BID #{@num_bids}\t #{bid[:bidder]}\t #{bid[:amt]}\t #{bid[:type]}\t #{bid[:last_secs]}\t:: #{@bidders[bid[:bidder]][:count]} so far"
printf("NEW BID %4d: %15s(%4d bids) %3.2f %15s - %2d seconds remaining\n",@num_bids, bid[:bidder], @bidders[bid[:bidder]][:count], bid[:amt], bid[:type], bid[:last_secs])
end

##determine unique bidders
@uniques = {}
bidders = @bids.reverse.map{|b| b[:bidder]}
@uniques[:u10] = bidders[0, 10].uniq.length
@uniques[:u20] = bidders[0, 20].uniq.length
#@uniques[:u30] = bidders[0, 30].uniq.length
#@uniques[:u40] = bidders[0, 40].uniq.length
#@uniques[:u50] = bidders[0, 50].uniq.length
@uniques[:u30] = bidders[0, 30].uniq.length
@uniques[:u40] = bidders[0, 40].uniq.length
@uniques[:u50] = bidders[0, 50].uniq.length

puts "Uniques: #{@uniques.inspect}"

Expand All @@ -58,10 +59,10 @@ def process_new_bids new_bids

def would_bid

return false if @num_bids < 25
return false if @uniques[:u10] > 6
return false if @uniques[:u20] > 9
return false if @autoq > 30
#return false if @num_bids < 25
return false if @uniques[:u10] > 8
#return false if @uniques[:u20] > 9
#return false if (@autoq > 40) && (@uniques[:u10] > 3)

return true
end
Expand Down
2 changes: 2 additions & 0 deletions lib/pa_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def observe_auction
while (new_bids.count > 0)
process_event :on_new_bids, new_bids
sleep 1.0
secs_since_refresh += 1
@last_secs = cur_secs
new_bids = get_new_bids
end

Expand Down
29 changes: 26 additions & 3 deletions site_bindings/quibids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ module QUIBIDS
@auction_els = nil

def start auction_id
@auction_id = auction_id if auction_id

@browser = Watir::Browser.new 'firefox'
@browser.goto "http://quibids.com/auctions/#{auction_id}"
goto_auction
end

def goto_auction
@browser.goto "http://quibids.com/auctions/#{@auction_id}"
end

def auction_name
Expand All @@ -24,7 +30,8 @@ def initialize_auction
@auction_els = {
:timer => @browser.div(:class => /timer2/ ),
:history => @browser.div(:id => 'bidding-history' ).table,
:bid_btn => @browser.link(:class => /^bid/ ),
#:bid_btn => @browser.link(:class => /^bid/ ),
:bid_btn => @browser.link(:id => "button_#{@auction_id}" ),
}

#confirm all the elements are accessible
Expand All @@ -38,6 +45,8 @@ def initialize_auction
end
puts "Found #{name}"
end

puts "Bid Btn: #{@auction_els[:bid_btn].html}"
end

def refresh_auction
Expand All @@ -56,7 +65,14 @@ def refresh_auction
end

def bid
@auction_els[:bid_btn].click
sleep 0.1 #this pause can be tweaked to give better last second catches
if seconds_left < 3
@auction_els[:bid_btn].click
puts "BID clicked!"
else
puts "SKIPPED BID at the last second.... timer didn't look ready'"

end
end

def seconds_left
Expand Down Expand Up @@ -95,4 +111,11 @@ def get_new_bids
bids
end

def login username, password
@browser.text_field(:name, 'username').set username
@browser.text_field(:name, 'password').set password
@browser.button(:id, 'login-btn').click
goto_auction
end

end

0 comments on commit a69a962

Please sign in to comment.