def gxp_spin_stops(forts, pgacc, step_location): for f in forts: if f.type == 1 and pokestop_spinnable(f, step_location): time.sleep(random.uniform(0.8, 1.8)) response = spin_pokestop_request(pgacc, f, step_location) time.sleep(random.uniform(2, 4)) # Don't let Niantic throttle. # Check for reCaptcha. if pgacc.has_captcha(): log.debug('Account encountered a reCaptcha.') return spin_result = response['FORT_SEARCH'].result if spin_result is 1: awards = parse_awarded_items( response['FORT_SEARCH'].items_awarded) log.info('GXP: Got {} items ({} balls) from Pokestop.'.format( awards['total'], awards['balls'])) cleanup_inventory(pgacc) return True elif spin_result is 2: log.debug('GXP: Pokestop was not in range to spin.') elif spin_result is 3: log.debug( 'GXP: Failed to spin Pokestop. Has recently been spun.') elif spin_result is 4: log.debug('GXP: Failed to spin Pokestop. Inventory is full.') cleanup_inventory(pgacc) elif spin_result is 5: log.debug( 'GXP: Maximum number of Pokestops spun for this day.') else: log.debug('GXP: Failed to spin a Pokestop. Unknown result %d.', spin_result)
def level_up_account(args, location, accounts, errors): while True: try: # Loop the queue. try: (account, error_count) = accounts.get(False) except Empty: break log.info('Starting account %s', account['username']) status = { 'type': 'Worker', 'message': 'Creating thread...', 'success': 0, 'fail': 0, 'noitems': 0, 'skip': 0, 'captcha': 0, 'username': '', 'proxy_display': None, 'proxy_url': None, } api = setup_api(args, status, account) api.set_position(*location) key = key_scheduler.next() api.activate_hash_server(key) check_login(args, account, api, status['proxy_url']) log.info('Account %s, level %d.', account['username'], account['level']) (error, forts) = get_location_forts(api, account, location) if error: errors[error].append(account) accounts.task_done() continue log.info('%d stops in range', len(forts)) for fort in forts: if pokestop_spinnable(fort, location): spin_pokestop(api, account, args, fort, location) log.info('Ended with account %s.', account['username']) log.info('Account %s, level %d.', account['username'], account['level']) except TooManyLoginAttempts: errors[ErrorType.login_error].append(account) except AccountBannedException: errors[ErrorType.banned].append(account) except Exception as e: if error_count < 2: log.exception('Exception in worker: %s. retrying.', e) accounts.put((account, error_count + 1)) else: errors[ErrorType.generic].append(account) accounts.task_done()
def level_up_account(args, location, accounts, errors): while True: try: # Loop the queue. try: (account, error_count) = accounts.get(False) except Empty: break log.info('Starting account %s', account['username']) status = { 'type': 'Worker', 'message': 'Creating thread...', 'success': 0, 'fail': 0, 'noitems': 0, 'skip': 0, 'captcha': 0, 'username': '', 'proxy_display': None, 'proxy_url': None, } api = setup_api(args, status, account) key = key_scheduler.next() api.set_position(*location) api.activate_hash_server(key) check_login(args, account, api, status['proxy_url']) log.info('Logged in account %s, level %d.', account['username'], account['level']) (error, forts) = get_location_forts(api, account, location) if error: errors[error].append(account) accounts.task_done() continue spinnable_pokestops = filter( lambda fort: pokestop_spinnable(fort, location), forts) # No stops in spin range. first_fort = forts[0] if not spinnable_pokestops: log.critical( 'No Pokestops in spinnable range. Please move' " the location. There's a Pokestop at" ' %s, %s.', first_fort.latitude, first_fort.longitude) os._exit(1) # Past this point, guaranteed to have a spinnable stop. fort = spinnable_pokestops[0] spin_pokestop(api, account, args, fort, location) log.info('Spun Pokestop with account %s, level %d.', account['username'], account['level']) except TooManyLoginAttempts: errors[ErrorType.login_error].append(account) except AccountBannedException: errors[ErrorType.banned].append(account) except Exception as e: if error_count < 2: log.exception('Exception in worker: %s. Retrying.', e) accounts.put((account, error_count + 1)) else: errors[ErrorType.generic].append(account) accounts.task_done()