def get_remaining_secs(self): seconds_left = '' while not seconds_left.isdigit(): countdownbox = self.browser.find_element_by_class_name("countdownbox") counter = countdownbox.text splitted_remaining_time = counter.split() if not splitted_remaining_time or splitted_remaining_time == [u'Gesloten'] or splitted_remaining_time[:10] == u"Een moment": log('Auction has ended.') make_screenshot(self.browser) return 0 if len(splitted_remaining_time) == 3: # includes hour remaining_hours = int(splitted_remaining_time[0].split("uur")[0]) elif len(splitted_remaining_time) == 2: # excludes hour remaining_hours = 0 else: # something is wrong log("DEBUG: Could not parse splitted_remaining_time '%s', auction is probably ending." % splitted_remaining_time) try: remaining_mins = int(splitted_remaining_time[-2].split("min")[0]) remaining_secs = int(splitted_remaining_time[-1].split("sec")[0]) seconds_left = remaining_secs seconds_left += (remaining_mins * 60) seconds_left += ((remaining_hours * 60) * 60) seconds_left = int(seconds_left) return seconds_left except ValueError: log("Caught ValueError") log(counter) raise
def do_login(self): log('Signing in') email = self.browser.find_element_by_id("loginEmail") passwd = self.browser.find_element_by_id('loginPassword') button = self.browser.find_element_by_id('login') email.send_keys(USERNAME) passwd.send_keys(PASSWORD) # button.click() keys = webdriver.common.keys.Keys() passwd.send_keys(keys.ENTER) counter = 0 log('Waiting max. 30 seconds') while not self.browser.find_elements_by_id("loggedinContainer"): time.sleep(1) counter += 1 log(counter) if counter > 30: log('Login failed.') make_screenshot(self.browser) return False else: log('Logged in successfully.') return True
def do_login(self): if self._is_logged_in(): log ("Already signed in") return True log('Signing in') click_element_when_available(self.browser.find_element_by_link_text, "Inloggen") time.sleep(1) email = [f for f in self.browser.find_elements_by_xpath("//input[@ng-model='email']") if f.is_displayed()][0] passwd = [f for f in self.browser.find_elements_by_xpath("//input[@ng-model='password']") if f.is_displayed()][0] button = [f for f in self.browser.find_elements_by_xpath("//input[@value='Login']") if f.is_displayed()][0] email.send_keys(USERNAME) passwd.send_keys(PASSWORD) button.click() counter = 0 log('Waiting max. 10 seconds') while not self._is_logged_in(): time.sleep(1) counter += 1 log(counter) if counter > 10: log('Login failed.') make_screenshot(self.browser) return False else: log('Logged in successfully.') return True
def get_remaining_secs(self): seconds_left = '' while not seconds_left.isdigit(): try: # it can take a few moments for the auction time to dynamically load. Before that, it's empty auction_time = "" while auction_time == "": auction_time = self.browser.find_element_by_class_name('auction-time').text.lower() hours = 0 mins = 0 if not 'sec' in auction_time: log('Auction has probably ended. Time string was: "%s"' % auction_time) make_screenshot(self.browser) return 0 if 'uur' in auction_time: hours, _, auction_time = auction_time.partition("uur") if 'min' in auction_time: mins, _, auction_time = auction_time.partition("min") secs, _, auction_time = auction_time.partition("sec") seconds_left = int(secs) seconds_left += (int(mins) * 60) seconds_left += ((int(hours) * 60) * 60) return seconds_left except Exception as e: log("EXCEPTION ! DEBUG: '%s'" % e) log('Returning 11 seconds') traceback.print_exc() ravenclient.captureException() return 11
def do_place_bid(self, price): log("ACTION is %s" % self.action) if self.action != "bid": log("We are doing a dry run. Not bidding! Creating screenshot instead.") make_screenshot(self.browser) return if int(price) > int(self.max_price): log("FAILSAFE (this should not happen): not placing bid of %s, it's higher than %s" % (price, self.max_price)) else: log("Placing bid of '%s' euro" % price ) ub = self.browser.find_element_by_id('userBid') # first clear the input field! log('DEBUG: Clearing input field') ub.clear() log('DEBUG: Sending %s to input field' % price) ub.send_keys(price) # log('DEBUG: Sending ENTER to input field') # keys = webdriver.common.keys.Keys() # ub.send_keys(keys.ENTER) log("DEBUG: Clicking Bid button") bb = self.browser.find_element_by_id('bidButton') bb.click() time.sleep(0.1) log('DEBUG: Clicking YES') click_element_when_available(self.browser.find_element_by_class_name, "yesButton") time.sleep(0.1) log('DEBUG: Clicking OK') click_element_when_available(self.browser.find_element_by_class_name, "yesButtonCentered") log('Placed bid for %s EUR' % price) time.sleep(0.2)
def brute_force_bid(site, max_price): """ Try to win the auction with the lowest bid, under max_price. Automatically over-bids other bidders. Always increments the current bid with one. Returns True if we won Returns False if we lost Always assumes that we won, we need to CHECK if we may have lost. """ log("Starting brute force bid with a max price of %s" % max_price) my_last_bid = 0 _current_bid = None while site.get_remaining_secs() > 0: __current_bid_last_time = _current_bid _current_bid = site.get_current_bid() log("DEBUG: Still in brute force bid mode. Current bid: %d | my last bid: %d" % (_current_bid, my_last_bid)) if _current_bid != __current_bid_last_time: _latest_bidder = site.get_latest_bidder() _remaining_secs = site.get_remaining_secs() log( "User '%s' just raised the bid to '%s' on %s seconds left." % (_latest_bidder, _current_bid, _remaining_secs) ) if _current_bid > my_last_bid and _current_bid < max_price: my_last_bid = _current_bid + 1 if my_last_bid <= max_price: log("Placing bid of %s" % my_last_bid) site.place_bid(my_last_bid) else: log("Current bid is higher than or equal to my max price") return False # time.sleep(0.1) # First, create a screenshot make_screenshot(site.browser) # We assume that we have won! But # Let's check if we have lost # Wait a few seconds log("Checking if we've lost") time.sleep(3) winning_bidder = site.get_latest_bidder() last_bid = site.get_current_bid() log("Winning bidder: '%s'" % winning_bidder) log("Winning bid: '%s'" % last_bid) # Double confirm that we have lost, cause it means that we will begin bidding again. if winning_bidder not in (VV_NAME, TV_NAME) and last_bid != my_last_bid: # Too bad, it sure looks like we lost log("Too bad, we lost") return False # Wait... we have won! log("It's possible that we've won.") return True