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()
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()
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
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
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
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'))