Exemplo n.º 1
0
    def get_latest_bidder(self):
        try:
            first_name = self.browser.find_elements_by_xpath('//span[@ng-bind="bid.customer.firstName"]')[0].text
            prefix = self.browser.find_elements_by_xpath('//span[@ng-bind="bid.customer.lastNamePrefix"]')[0].text
            last_name = self.browser.find_elements_by_xpath('//span[@ng-bind="bid.customer.lastName"]')[0].text
            if prefix:
                return "%s %s %s" % (first_name, prefix, last_name)
            return "%s %s" % (first_name, last_name)

        except:
            ravenclient.captureException()
            return 'unknown'
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
def begin(url):
    try:
        if "vakantieveilingen.nl" in url:
            log("Using VakantieVeilingen engine")
            Site = VakantieVeilingen
        elif "ticketveiling.nl" in url:
            log("Using TicketVeiling engine")
            Site = TicketVeiling
        else:
            print "Cannot detect URL"
            sys.exit(1)

        SITE = None  # So we can check if var has been initialized below
        browser = start_browser(url, browser=USE_BROWSER)
        SITE = Site(browser=browser, max_price=max_price, action=ACTION)

        log("Remaining seconds: %s" % SITE.get_remaining_secs())

        if SITE.get_remaining_secs() is not None and SITE.get_remaining_secs() > 200:
            wait_secs = SITE.get_remaining_secs() - 200
            datetime_of_next_action = datetime.datetime.now() + datetime.timedelta(seconds=wait_secs)
            log(
                "Remaining seconds: More than 120 secs: '%s'. Scheduling a restart in '%s' seconds"
                % (SITE.get_remaining_secs(), wait_secs)
            )
            log("This would be around %s" % datetime_of_next_action)
            scheduler.enter(wait_secs, 0, begin, (url,))
            browser.quit()

        elif SITE.get_remaining_secs() is not None and SITE.get_remaining_secs() > 0:

            # Only login when the current bid is below our max price.
            if SITE.get_current_bid() < max_price:
                log(
                    "Current bid (%s) is lower than our max price (%s); logging in"
                    % (SITE.get_current_bid(), max_price)
                )
                login = True
            else:
                log(
                    "Not logging in; current bid (%s) is higher than, or equal to, our max price (%s)."
                    % (SITE.get_current_bid(), max_price)
                )
                login = False

            if login and not SITE.do_login():
                scheduler.enter(0, 1, begin, (url,))

            else:
                # Close cookie dialog that might have re-appeared after signing in
                close_cookie_dialogs(browser)

                while SITE.get_remaining_secs() > 0:
                    global _current_bid
                    global _latest_bidder
                    global _remaining_secs

                    # Used to check if current bid has changed
                    prev_bid = _current_bid

                    _remaining_secs = SITE.get_remaining_secs()
                    _current_bid = SITE.get_current_bid()
                    _latest_bidder = SITE.get_latest_bidder()

                    if prev_bid != _current_bid and _current_bid != 0 and prev_bid is not None:
                        sys.stdout.write("\n")
                        sys.stdout.flush()
                        log(
                            "User '%s' just raised the bid to '%s' on %s seconds left."
                            % (_latest_bidder, _current_bid, _remaining_secs)
                        )

                    if _remaining_secs < 6 and _current_bid < max_price:
                        we_won = brute_force_bid(SITE, max_price)
                        if we_won:
                            log("Exiting!")
                            browser.quit()
                            sys.exit(0)

                    time.sleep(0.5)

                else:
                    # The auction seems to be ended
                    time.sleep(5)
                    _current_bid = SITE.get_current_bid()
                    _latest_bidder = SITE.get_latest_bidder()
                    log("Auction has ended, winning bid is '%s' by '%s'." % (_current_bid, _latest_bidder))
                    save_winning_bid_and_log_history(bid=_current_bid, bidder=_latest_bidder)

                    browser.quit()
                    scheduler.enter(5, 1, begin, (url,))

        elif SITE.get_remaining_secs() in (None, 0):
            log("Auction seems to be closed. Scheduling restart in 60 secs.")
            scheduler.enter(60, 1, begin, (url,))

        else:
            log("This should not happen.")

    except WebDriverException as e:
        # log("Caught WebDriverException, the browser probably crashed. Forcing browser quit and rescheduling restart in 10 seconds.")
        # log("The exception was: '%s'" % e)
        # traceback.print_exc()
        log("Caught WebDriverException. Trying a refresh.")
        if SITE is None:
            log("Nope, SITE is None - capturing exception")
            if RAVEN_ENABLED:
                ravenclient.captureException()
            log("Scheduling a restart")
            scheduler.enter(15, 1, begin, (url,))
            return
        try:
            SITE.browser.refresh()
        except:
            if RAVEN_ENABLED:
                ravenclient.captureException()
            log("That went wrong. Restarting browser")
            SITE.browser.quit()
            scheduler.enter(15, 1, begin, (url,))

    except Exception as e:
        log(
            "Caught unexpected exception: '%s'. Forcing browser quit and rescheduling restart in 60 seconds."
            % e.message
        )
        log("The exception was: '%s'" % e)
        traceback.print_exc()
        if RAVEN_ENABLED:
            ravenclient.captureException()

        try:
            SITE.browser.quit()
        except:
            pass
        scheduler.enter(60, 1, begin, (url,))