Esempio n. 1
0
def harvest_tokens_manually():
    """
    Harvest tokens manually
    """
    print (d_(), s_('Manual Token Harvest'), lb_('Number of tokens harvested: %d' % len(captcha_tokens)))

    # Run the harvest server
    # XXX: This threading module is deprecated
    thread.start_new_thread(harvest_server.run, ())

    browser = get_chromedriver(chrome_folder_location='ChromeTokenHarvestFolder', window_size=['640,640'])
    url = 'http://{0}:{1}{2}'.format(user_config.harvestDomain, 5000, '')  # Flask runs on port 5000 by default.
    while len(captcha_tokens) < user_config.numberOfTokens:
        browser.get(url)
        main_window = browser.current_window_handle

        try:
            activate_captcha(driver=browser)
        except:
            print (d_(), x_('Page Load Failed'), lr_('Falling back to 2captcha'))
            browser.quit()
            return

        check_solution(driver=browser, main_window=main_window)
        token = get_token(driver=browser, main_window=main_window)
        if token is not None:
            if len(captcha_tokens) == 0:
                start_time = time.time()
            captcha_tokens.append(token)
            print (d_(), s_('Token Added'))
            print (d_(), s_('Manual Token Harvest'), lb_('Number of tokens harvested: %d' % len(captcha_tokens)))
        current_time = time.time()
        elapsed_time = current_time - start_time
        print (d_(), s_('Total Time Elapsed'), lb_(round(elapsed_time, 2), 'seconds'))
    browser.quit()
Esempio n. 2
0
def get_variant_response():
    """
    Gets variant-level inventory data.
    """
    headers = {'User-Agent': get_random_user_agent()}
    session = requests.Session()
    session.verify = False
    session.cookies.clear()

    # Not sure why I even bother making a case for Portugal if dude on twitter
    # keeps telling it doesnt work. Da fuq is MLT?
    if user_config.market == 'PT':
        url = ('http://www.{0}/on/demandware.store/Sites-adidas-'
               '{1}-Site/MLT/Product-GetVariants?pid={2}').format(
                   user_config.marketDomain,
                   user_config.marketLocale,
                   user_config.masterPid,
               )
    else:
        url = ('http://www.{0}/on/demandware.store/Sites-adidas-'
               '{1}-Site/{2}/Product-GetVariants?pid={3}').format(
                   user_config.marketDomain,
                   user_config.marketLocale,
                   user_config.market,
                   user_config.masterPid,
               )

    if user_config.debug:
        print(d_(), z_('Debug'), o_(url))

    return session.get(url=url, headers=headers)
Esempio n. 3
0
def get_token(driver, main_window):
    """
    We parse the token from the page
    """
    token = None
    driver.switch_to.window(main_window)
    try:
        submit = WebDriverWait(driver, user_config.sleeping).until(
            expected_conditions.presence_of_element_located((By.ID, 'submit')))
        submit.click()
        time.sleep(1)
    except:
        print(d_(), x_('Captcha Submit'), lr_('Failed to click submit'))

    token_element = driver.find_element_by_css_selector('p#token')
    token = token_element.get_attribute('value')
    if token is not None:
        print(d_(), s_('Get Token'), lb_(token))
    return token
Esempio n. 4
0
def check_solution(driver, main_window):
    """
    Check to see if we solved the captcha
    """
    solved = False
    while not solved:
        driver.switch_to.window(main_window)
        try:
            iframe = driver.find_element_by_css_selector('iframe[src*="api2/anchor"]')
        except:
            print (d_(), x_('Check Solution'), lr_('Failed to find checkbox'))
            return
        driver.switch_to_frame(iframe)
        try:
            driver.find_element_by_xpath('//span[@aria-checked="true"]')
            print (d_(), s_('Check Solution'), lb_('Solved'))
            solved = True
        except:
            solved = False
        time.sleep(1)
    return solved
Esempio n. 5
0
def activate_captcha(driver):
    """
    Activate the catpcha widget
    """
    iframe = driver.find_element_by_css_selector('iframe[src*="api2/anchor"]')
    driver.switch_to_frame(iframe)
    try:
        checkbox = WebDriverWait(driver, user_config.sleeping).until(
            expected_conditions.presence_of_element_located((By.ID, 'recaptcha-anchor')))
    except:
        try:
            checkbox = WebDriverWait(driver, user_config.sleeping).until(
                expected_conditions.presence_of_element_located((By.ID, 'recaptcha-anchor')))
        except:
            print (d_(), x_('Activate Captcha'), lr_('Failed to find checkbox'))
    checkbox.click()
Esempio n. 6
0
def get_client_response():
    """
    Gets client-level inventory data.
    """
    headers = {'User-Agent': get_random_user_agent()}
    session = requests.Session()
    session.verify = False
    session.cookies.clear()
    skus = ','.join([
        '{sku}_{size_id}'.format(sku=user_config.masterPid, size_id=x)
        for x in range(510, 820, 10)
    ])

    # Other countries will use US format like MX.
    # They can just request US value for parametersLocale in config.cfg
    if user_config.parametersLocale == 'US':
        url = ('http://{0}-us-adidasgroup.demandware.net/s/adidas-{1}'
               '/dw/shop/v15_6/products/({2})'
               '?client_id={3}&expand=availability,variations,prices').format(
                   user_config.apiEnv,
                   user_config.marketLocale,
                   skus,
                   user_config.clientId,
               )
    else:
        url = ('http://{0}-store-adidasgroup.demandware.net/s/adidas-{1}'
               '/dw/shop/v15_6/products/({2})'
               '?client_id={3}&expand=availability,variations,prices').format(
                   user_config.apiEnv,
                   user_config.marketLocale,
                   skus,
                   user_config.clientId,
               )
    if user_config.debug:
        print(d_(), z_('Debug'), o_(url))

    return session.get(url=url, headers=headers)
Esempio n. 7
0
    def validate_config(self):
        """
        Validate the user-set config.
        """
        nah = False
        if self.marketLocale == 'US' and self.parametersLocale != 'US':
            print(
                d_(), z_('config.cfg'),
                lr_('Invalid marketLocale and parametersLocale combination.'))
            nah = True

        if self.useClientInventory and self.useVariantInventory:
            print(d_(), z_('config.cfg'),
                  lr_('You should not set both inventory methods to True.'))

        if not self.manuallyHarvestTokens:
            # User is not token harvesting
            if self.processCaptcha:
                if self.apikey2captcha == 'xXx':
                    print(
                        d_(), z_('config.cfg'),
                        lr_('You need a valid apikey2captcha if you '
                            'want to use 2captcha service! Visit 2captcha.com')
                    )
                    nah = True
                if self.proxy2Captcha == 'localhost':
                    print(
                        d_(), z_('config.cfg'),
                        lr_('Unless you are testing - you should consider '
                            'providing an IP whitelisted proxy for 2captcha to use.'
                            ))
        else:
            # User is token harvesting
            if not self.processCaptcha:
                # This should have been automatically set in the printRunParameters
                # but lets check.
                print(
                    d_(), z_('config.cfg'),
                    lr_('You want to manually harvest tokens but you have not set processCaptcha to True. '
                        'Much reading you have done.'))
                nah = True
            if self.numberOfTokens < 1:
                print(
                    d_(), z_('config.cfg'),
                    lr_('Your config.cfg makes no f*****g sense. Why is numberOfTokens set to zero? '
                        'And why are you requesting to harvest tokens?'))
                nah = True
            if self.numberOfTokens > 5:
                print(
                    d_(), z_('config.cfg'), '',
                    lr_('You requested to harvest a large number of tokens. '
                        'You wont be able to ATC until after you harvest all '
                        'of the tokens. And tokens have a lifespan of ~ '
                        '120 seconds.'))

        if self.sleeping < 3:
            print(
                d_(), z_('config.cfg'),
                lr_('Your sleeping value is less than 3 seconds. It might not offer enough time between events.'
                    ))
        if self.masterPid in str(hyped_skus):
            if not self.processCaptchaDuplicate:
                print(
                    d_(), z_('config.cfg'),
                    lr_('This item is likely to make use of a captcha duplicate.'
                        ))
            if 'neverywhere' in self.cookies:
                print(d_(), z_('config.cfg'),
                      lr_('This item is likely to make use of a cookie.'))
        if not self.debug:
            print(
                d_(), z_('config.cfg'),
                lr_('debug is turned off. If you run into any issues dont bother tweeting them to me. '
                    'Because I will ask you why debug is turned off.'))

        return not nah
Esempio n. 8
0
 def print_config(self):
     """
     Print out config for debugging.
     """
     print(d_(), s_('Market Locale'), lb_(self.marketLocale))
     print(d_(), s_('Parameters Locale'), lb_(self.parametersLocale))
     print(d_(), s_('Market'), lb_(self.market))
     print(d_(), s_('Market Domain'), lb_(self.marketDomain))
     print(d_(), s_('API Environment'), lb_(self.apiEnv))
     print(d_(), s_('Market Client ID'), lb_(self.clientId))
     print(d_(), s_('Market Site Key'), lb_(self.sitekey))
     print(d_(), s_('Captcha Duplicate'), lb_(self.duplicateField))
     print(d_(), s_('Cookie'), lb_(self.cookies))
     print(d_(), s_('Preload URL'), lb_(self.preloadURL))
     print(d_(), s_('Process Captcha'), lb_(self.processCaptcha))
     print(d_(), s_('Use Duplicate'), lb_(self.processCaptchaDuplicate))
     print(d_(), s_('Product ID'), lb_(self.masterPid))
     print(d_(), s_('Desired Size'), lb_(self.mySizes))
     print(d_(), s_('Manual Token Harvest'),
           lb_(self.manuallyHarvestTokens))
     print(d_(), s_('Tokens to Harvest'), lb_(self.numberOfTokens))
     print(d_(), s_('Harvest Domain'), lb_(self.harvestDomain))
     print(d_(), s_('Sleeping'), lb_(self.sleeping))
     print(d_(), s_('Debug'), lb_(self.debug))
     print(d_(), s_('External Script URL'), lb_(self.scriptURL))
     print(d_(), s_('Pause Between ATC'), lb_(self.pauseBeforeBrowserQuit))
     print(d_(), s_('Use Link Injection'), lb_(self.useInjectionMethod))
Esempio n. 9
0
import sys

from cart import process_add_to_cart
from product import get_product_info, print_product_info
from settings import exit_code, user_config
from utils import d_, lr_, x_

if __name__ == '__main__':
    # Print the run parameters
    user_config.print_config()

    # Check for dumb asses
    if not user_config.validate_config():
        sys.stdout.flush()
        sys.exit(exit_code)

    # Get product info
    product_info = get_product_info()

    # Print product info
    print_product_info(product_info)

    # If product count is not zero process add to cart
    if product_info['productCount'] > 0:
        process_add_to_cart(product_info)
    elif product_info['productCount'] == -1:
        print(d_(), x_('Variant Count'), lr_('-1'))
        process_add_to_cart(product_info)
    else:
        print(d_(), x_('Variant Count'), lr_('0'))
Esempio n. 10
0
def get_token_from_2captcha():
    session = requests.Session()
    session.verify = False
    session.cookies.clear()
    pageurl = 'http://www.{0}'.format(user_config.marketDomain)
    print(d_(), s_('pageurl'), lb_(pageurl))
    print(d_(), s_('sitekey'), lb_(user_config.sitekey))
    while True:
        data = {
            'key': user_config.apikey2captcha,
            'action': 'getbalance',
            'json': 1,
        }
        response = session.get(url='http://2captcha.com/res.php', params=data)
        if "ERROR_WRONG_USER_KEY" in response.text:
            print(d_(), x_('Response'), y_(response.text))
            sys.exit(exit_code)

        try:
            JSON = response.json()
        except:
            raise
            print(d_(), x_('Sleeping'), y_(user_config.sleeping, 'seconds'))
            time.sleep(user_config.sleeping)
            continue

        if JSON['status'] == 1:
            balance = JSON['request']
            print(d_(), s_('Balance'), lb_('${0}'.format(balance)))
        else:
            print(d_(), x_('Balance'))

        CAPTCHAID = None
        proceed = False
        while not proceed:
            data = {
                'key': user_config.apikey2captcha,
                'method': 'userrecaptcha',
                'googlekey': user_config.sitekey,
                'proxy': user_config.proxy2Captcha,
                'proxytype': 'HTTP',
                'pageurl': pageurl,
                'json': 1
            }
            response = session.post(url='http://2captcha.com/in.php',
                                    data=data)
            try:
                JSON = response.json()
            except:
                print(d_(), x_('Response'), y_(response.text))
                print(d_(), x_('Sleeping'), y_(user_config.sleeping,
                                               'seconds'))
                time.sleep(user_config.sleeping)
                continue

            if JSON['status'] == 1:
                CAPTCHAID = JSON['request']
                proceed = True
                print(d_(), s_('Captcha ID'), lb_(CAPTCHAID))
            else:
                print(d_(), x_('Response'), y_(response.text))
                print(d_(), x_('Sleeping'), y_(user_config.sleeping,
                                               'seconds'))
                time.sleep(user_config.sleeping)
        print(
            d_(), s_('Waiting'),
            '%d seconds before polling for Captcha response' %
            user_config.sleeping)
        time.sleep(user_config.sleeping)

        TOKEN = None
        proceed = False
        while not proceed:
            data = {
                'key': user_config.apikey2captcha,
                'action': 'get',
                'json': 1,
                'id': CAPTCHAID,
            }
            response = session.get(url='http://2captcha.com/res.php',
                                   params=data)
            JSON = response.json()
            if JSON['status'] == 1:
                TOKEN = JSON['request']
                proceed = True
                print(d_(), s_('Token ID'), lb_(TOKEN))
            else:
                print(d_(), x_('Response'), y_(response.text))
                print(d_(), x_('Sleeping'), y_(user_config.sleeping,
                                               'seconds'))
                time.sleep(user_config.sleeping)

        data = {
            'key': user_config.apikey2captcha,
            'action': 'getbalance',
            'json': 1,
        }
        response = session.get(url='http://2captcha.com/res.php', params=data)
        JSON = response.json()
        if JSON['status'] == 1:
            balance = JSON['request']
            print(d_(), s_('Balance'), lb_('${0}'.format(balance)))
        else:
            print(d_(), x_('Balance'))
        if TOKEN is not None:
            return TOKEN