From a69a9624945a92fea54ab571e0a6a8a1898aa3b0 Mon Sep 17 00:00:00 2001 From: mr-rubot Date: Sat, 10 Sep 2011 11:58:19 -0400 Subject: [PATCH] added login, a bunch of minor tweaks and bug fixes --- bin/pa_auction_bot.rb | 10 ++++++++++ bots/bidder.rb | 6 +++--- bots/bidder_model.rb | 17 +++++++++-------- lib/pa_observer.rb | 2 ++ site_bindings/quibids.rb | 29 ++++++++++++++++++++++++++--- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/bin/pa_auction_bot.rb b/bin/pa_auction_bot.rb index 348b6ef..0c2f5f4 100755 --- a/bin/pa_auction_bot.rb +++ b/bin/pa_auction_bot.rb @@ -8,6 +8,7 @@ def parse_cmd_line options = { :hooks_file => 'bots/csv_logger.rb', :site => 'QUIBIDS', + :login => false, } optparse = OptionParser.new do |opts| @@ -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! @@ -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 diff --git a/bots/bidder.rb b/bots/bidder.rb index 21e5c5f..54c32a4 100644 --- a/bots/bidder.rb +++ b/bots/bidder.rb @@ -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 } diff --git a/bots/bidder_model.rb b/bots/bidder_model.rb index 4a38188..6a21ab6 100644 --- a/bots/bidder_model.rb +++ b/bots/bidder_model.rb @@ -25,7 +25,8 @@ 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 @@ -33,9 +34,9 @@ def process_new_bids new_bids 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}" @@ -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 diff --git a/lib/pa_observer.rb b/lib/pa_observer.rb index c38dca3..52ee34c 100644 --- a/lib/pa_observer.rb +++ b/lib/pa_observer.rb @@ -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 diff --git a/site_bindings/quibids.rb b/site_bindings/quibids.rb index c81dca6..69a7601 100644 --- a/site_bindings/quibids.rb +++ b/site_bindings/quibids.rb @@ -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 @@ -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 @@ -38,6 +45,8 @@ def initialize_auction end puts "Found #{name}" end + + puts "Bid Btn: #{@auction_els[:bid_btn].html}" end def refresh_auction @@ -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 @@ -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 \ No newline at end of file