def search(self, position, num_steps): if self.api._auth_provider and self.api._auth_provider._ticket_expire: if isinstance(self.api._auth_provider._ticket_expire, (int, long)): remaining_time = self.api._auth_provider._ticket_expire / 1000.0 - time.time() if remaining_time > 60: logger.info("Skipping Pokemon Go login process since already logged in for another {:.2f} seconds".format(remaining_time)) else: self.login() else: logger.warn("skipping login since _ticket_expire was a token.") else: self.login() all_pokemon = {} num_retries = 0 for step, coord in enumerate(generate_location_steps(position, num_steps, self.visible_range_meters), 1): lat = coord[0] lng = coord[1] self.api.set_position(*coord) cell_ids = get_cell_ids(lat, lng) timestamps = [0,] * len(cell_ids) response_dict = None pokemons = None while pokemons is None: try: logging.info('get map objects....') response_dict = self.api.get_map_objects(latitude = f2i(lat), longitude = f2i(lng), since_timestamp_ms = timestamps, cell_id = cell_ids) except: logging.warn('exception happened on get_map_objects api call', exc_info=True) try: pokemons = parse_map(response_dict) logging.warn('pokemons = %s', pokemons) except: logger.warn('exception happened on parse_map', exc_info=True) if not response_dict or pokemons is None: if num_retries < MAX_NUM_RETRIES: num_retries += 1 logger.warn('get_map_objects failed, retrying in %s seconds, %s retries', REQ_SLEEP, num_retries) time.sleep(self.min_refresh_seconds) else: logger.warn('MAX_NUM_RETRIES exceeded, retrying login...') self.login() raise StopIteration for key in pokemons.keys(): if not key in all_pokemon: pokemon = pokemons[key] all_pokemon[key] = pokemon yield pokemon # else: # logger.info("have duplicate poke: %s", key) total_steps = (3 * (num_steps**2)) - (3 * num_steps) + 1 logger.info('Completed {:5.2f}% of scan.'.format(float(step) / total_steps * 100)) time.sleep(self.min_refresh_seconds)
def search(self, lat, lng, step_limit, step_size): if self.api._auth_provider and self.api._auth_provider._ticket_expire: if isinstance(self.api._auth_provider._ticket_expire, (int, long)): remaining_time = self.api._auth_provider._ticket_expire / 1000.0 - time.time() if remaining_time > 60: logger.info("Skipping Pokemon Go login process since already logged in for another {:.2f} seconds".format(remaining_time)) else: self.login() else: logger.warn("skipping login since _ticket_expire was a token.") else: self.login() # coords = generate_spiral(lat, lng, step_size, step_limit) coords = generate_location_steps(lat, lng, step_size, step_limit) all_pokemon = {} i = 1 for coord in coords: lat = coord['lat'] lng = coord['lng'] self.api.set_position(lat, lng, 0) cell_ids = get_cell_ids(lat, lng) timestamps = [0,] * len(cell_ids) self.api.get_map_objects(latitude = f2i(lat), longitude = f2i(lng), since_timestamp_ms = timestamps, cell_id = cell_ids) response_dict = self.api.call() while not response_dict: logger.info('Map Download failed. Trying again.') self.api.get_map_objects(latitude = f2i(lat), longitude = f2i(lng), since_timestamp_ms = timestamps, cell_id = cell_ids) response_dict = self.api.call() time.sleep(REQ_SLEEP) try: pokemons, pokestops, gyms = parse_map(response_dict) except KeyError as e: logger.error('failed to parse map with key error: %s', e) for key in pokemons.keys(): if not key in all_pokemon: pokemon = pokemons[key] expires_in = pokemon['disappear_time'] - datetime.utcnow() pokemon_id = pokemon['pokemon_id'] pokedata = Pokedata.get(pokemon_id) pokemon['name'] = pokedata['name'] pokemon['rarity'] = pokedata['rarity'] pokemon['key'] = key logger.info("adding pokemon: %s - %s, rarity: %s, expires in: %s", pokemon_id, pokemon['name'], pokemon['rarity'], expires_in) all_pokemon[key] = pokemon # else: # logger.info("have duplicate poke: %s", key) logger.info('Completed {:5.2f}% of scan.'.format(float(i) / step_limit**2*100)) i += 1 time.sleep(REQ_SLEEP) return all_pokemon
def search(self, position, num_steps): if self.api._auth_provider and self.api._auth_provider._ticket_expire: if isinstance(self.api._auth_provider._ticket_expire, (int, long)): remaining_time = self.api._auth_provider._ticket_expire / 1000.0 - time.time() if remaining_time > 60: logger.info("Skipping Pokemon Go login process since already logged in for another {:.2f} seconds".format(remaining_time)) else: self.login() else: logger.warn("skipping login since _ticket_expire was a token.") else: self.login() all_pokemon = {} for step, coord in enumerate(generate_location_steps(position, num_steps), 1): lat = coord[0] lng = coord[1] self.api.set_position(*coord) cell_ids = get_cell_ids(lat, lng) timestamps = [0,] * len(cell_ids) response_dict = None while not response_dict: try: self.api.get_map_objects(latitude = f2i(lat), longitude = f2i(lng), since_timestamp_ms = timestamps, cell_id = cell_ids) response_dict = self.api.call() except: logging.warn('exception happened on get_map_objects api call', exc_info=True) if not response_dict: logger.warn('get_map_objects failed, retrying in %s seconds...', REQ_SLEEP) time.sleep(REQ_SLEEP) # try: pokemons = parse_map(response_dict) # except KeyError as e: # logger.error('failed to parse map with key error: %s', e) for key in pokemons.keys(): if not key in all_pokemon: pokemon = pokemons[key] all_pokemon[key] = pokemon yield pokemon # else: # logger.info("have duplicate poke: %s", key) total_steps = (3 * (num_steps**2)) - (3 * num_steps) + 1 logger.info('Completed {:5.2f}% of scan.'.format(float(step) / total_steps * 100)) time.sleep(REQ_SLEEP)
def search(self, lat, lng, step_limit, step_size): if self.api._auth_provider and self.api._auth_provider._ticket_expire: if isinstance(self.api._auth_provider._ticket_expire, (int, long)): remaining_time = self.api._auth_provider._ticket_expire / 1000.0 - time.time( ) if remaining_time > 60: logger.info( "Skipping Pokemon Go login process since already logged in for another {:.2f} seconds" .format(remaining_time)) else: self.login() else: logger.warn("skipping login since _ticket_expire was a token.") else: self.login() # coords = generate_spiral(lat, lng, step_size, step_limit) coords = generate_location_steps(lat, lng, step_size, step_limit) all_pokemon = {} i = 1 for coord in coords: lat = coord['lat'] lng = coord['lng'] self.api.set_position(lat, lng, 0) cell_ids = get_cell_ids(lat, lng) timestamps = [ 0, ] * len(cell_ids) self.api.get_map_objects(latitude=f2i(lat), longitude=f2i(lng), since_timestamp_ms=timestamps, cell_id=cell_ids) response_dict = self.api.call() while not response_dict: logger.info('Map Download failed. Trying again.') self.api.get_map_objects(latitude=f2i(lat), longitude=f2i(lng), since_timestamp_ms=timestamps, cell_id=cell_ids) response_dict = self.api.call() time.sleep(REQ_SLEEP) try: pokemons, pokestops, gyms = parse_map(response_dict) except KeyError as e: logger.error('failed to parse map with key error: %s', e) for key in pokemons.keys(): if not key in all_pokemon: pokemon = pokemons[key] pokemon_id = pokemon['pokemon_id'] pokedata = Pokedata.get(pokemon_id) pokemon['name'] = pokedata['name'] pokemon['rarity'] = pokedata['rarity'] pokemon['key'] = key all_pokemon[key] = pokemon yield pokemon # else: # logger.info("have duplicate poke: %s", key) logger.info('Completed {:5.2f}% of scan.'.format( float(i) / step_limit**2 * 100)) i += 1 time.sleep(REQ_SLEEP)