コード例 #1
0
    def path(self, from_lat, form_lng, to_lat, to_lng):
        # type: (float, float, float, float) -> List[(float, float)]
        if self.config.debug:
            logger.log("[#] Asking google for directions")

        gmaps = googlemaps.Client(key=self.config.gmapkey)

        now = datetime.now()
        start = "{},{}".format(from_lat, form_lng)
        end = "{},{}".format(to_lat, to_lng)
        directions_result = gmaps.directions(start,
                                             end,
                                             mode="walking",
                                             departure_time=now)

        if len(directions_result) and len(directions_result[0]["legs"]):
            steps = []
            for leg in directions_result[0]["legs"]:
                for step in leg["steps"]:
                    steps.append((step["end_location"]["lat"],
                                  step["end_location"]["lng"]))

            # Finally, walk to the stop's exact location as google can snap it's destinations to the
            # nearest road/path/address
            steps.append((to_lat, to_lng))

            return steps
        else:
            # If google doesn't know the way, then we just have to go as the crow flies
            return [(to_lat, to_lng)]
コード例 #2
0
ファイル: stepper.py プロジェクト: Saturate/OpenPoGoBot
    def walk_to(self, speed, lat, lng, alt):
        position_lat, position_lng, _ = self.api_wrapper.get_position()

        # ask google for directions
        if self.config.google_directions and self.config.gmapkey:

            logger.log("[#] Asking google for directions")
            gmaps = googlemaps.Client(key=self.config.gmapkey)

            now = datetime.now()
            start = "{},{}".format(position_lat, position_lng)
            end = "{},{}".format(lat, lng)
            directions_result = gmaps.directions(start, end, mode="walking", departure_time=now)

            if len(directions_result) and len(directions_result[0]["legs"]):
                for leg in directions_result[0]["legs"]:
                    for step in leg["steps"]:
                        self._do_walk_to(speed, step["start_location"]["lat"], step["start_location"]["lng"],
                                         step["end_location"]["lat"], step["end_location"]["lng"], alt, 10)
            else:
                # If google doesn't know the way, then we just have to go as the crow flies
                self._do_walk_to(speed, position_lat, position_lng, lat, lng, alt, 25)

        else:
            self._do_walk_to(speed, position_lat, position_lng, lat, lng, alt, 25)

        logger.log("[#] Walking Finished")
コード例 #3
0
ファイル: stepper.py プロジェクト: tegob/OpenPoGoBot
    def step(self, destination):
        # type: (Destination) -> None
        self.bot.fire("walking_started",
                      coords=(destination.target_lat, destination.target_lng,
                              destination.target_alt))

        dist = distance(self.current_lat, self.current_lng,
                        destination.target_lat, destination.target_lng)

        if destination.name:
            logger.log("Walking towards {} ({} away, eta {})".format(
                destination.name, format_dist(dist, self.config.distance_unit),
                format_time(len(destination.steps))),
                       prefix="Navigation")

        for step in destination.steps:
            self._step_to(*step)
            yield step

        if destination.name:
            logger.log("Arrived at {} ({} away)".format(
                destination.name, format_dist(dist,
                                              self.config.distance_unit)),
                       prefix="Navigation")

        self.bot.fire("walking_finished",
                      coords=(destination.target_lat, destination.target_lng,
                              destination.target_alt))
コード例 #4
0
    def work(self):
        if not self.config.catch_pokemon:
            return

        if 'catchable_pokemons' in self.cell and len(self.cell['catchable_pokemons']) > 0:
            logger.log('Something rustles nearby!')
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            self.cell['catchable_pokemons'].sort(
                key=
                lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))

            user_web_catchable = 'web/catchable-%s.json' % (self.config.username)
            for pokemon in self.cell['catchable_pokemons']:
                with open(user_web_catchable, 'w') as outfile:
                    json.dump(pokemon, outfile)

            return self.catch_pokemon(self.cell['catchable_pokemons'][0])

        if 'wild_pokemons' in self.cell and len(self.cell['wild_pokemons']) > 0:
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            self.cell['wild_pokemons'].sort(
                key=
                lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))
            return self.catch_pokemon(self.cell['wild_pokemons'][0])
コード例 #5
0
ファイル: __init__.py プロジェクト: AlexDevelop/OpenPoGoBot
    def start(self):
        self._setup_logging()
        self._init_plugins()
        self._setup_api()
        random.seed()

        self.stepper = Stepper(self)
        self.mapper = Mapper(self)

        if self.config.navigator == 'fort':
            self.navigator = FortNavigator(self)  # pylint: disable=redefined-variable-type
        elif self.config.navigator == 'waypoint':
            self.navigator = WaypointNavigator(self)  # pylint: disable=redefined-variable-type
        elif self.config.navigator == 'camper':
            self.navigator = CamperNavigator(self)  # pylint: disable=redefined-variable-type

        self.fire('bot_initialized')

        if self.config.initial_transfer:
            self.fire("pokemon_bag_full")

        if self.config.recycle_items:
            self.fire("item_bag_full")

        logger.log('[#]')
        self.update_player_and_inventory()
コード例 #6
0
ファイル: stepper.py プロジェクト: Saturate/OpenPoGoBot
    def _do_walk_to(self, speed, from_lat, from_lng, to_lat, to_lng, alt, delta_factor):
        # type: (float, float, float, float, float, float, float) -> None

        dist = distance(from_lat, from_lng, to_lat, to_lng)
        steps = (dist / (self.AVERAGE_STRIDE_LENGTH_IN_METRES * speed))

        logger.log("[#] Walking from " + str((from_lat, from_lng)) + " to " + str(
            str((to_lat, to_lng))) + " for approx. " + str(format_time(ceil(steps))))
        if steps != 0:
            d_lat = (to_lat - from_lat) / steps
            d_long = (to_lng - from_lng) / steps

            for _ in range(int(steps)):
                position_lat, position_lng, _ = self.api_wrapper.get_position()
                c_lat = position_lat + d_lat + random_lat_long_delta(delta_factor)
                c_long = position_lng + d_long + random_lat_long_delta(delta_factor)
                self.api_wrapper.set_position(c_lat, c_long, alt)

                self.bot.heartbeat()
                sleep(1)  # sleep one second plus a random delta

                position_lat, position_lng, _ = self.api_wrapper.get_position()
                self._work_at_position(position_lat, position_lng)

            self.bot.heartbeat()
コード例 #7
0
    def _release_evolved(self, release_cand_list_ids):
        self.api.get_inventory()
        response_dict = self.api.call()
        cache = {}

        try:
            reduce(dict.__getitem__, [
                "responses", "GET_INVENTORY", "inventory_delta",
                "inventory_items"
            ], response_dict)
        except KeyError:
            pass
        else:
            release_cand_list = self._sort_by_cp(
                response_dict['responses']['GET_INVENTORY']['inventory_delta']
                ['inventory_items'])
            release_cand_list = [
                x for x in release_cand_list if x[0] in release_cand_list_ids
            ]

            ## at this point release_cand_list contains evolved pokemons data
            for cand in release_cand_list:
                pokemon_id = cand[0]
                pokemon_name = cand[1]
                pokemon_cp = cand[2]
                pokemon_potential = cand[3]

                if self.should_release_pokemon(pokemon_name, pokemon_cp,
                                               pokemon_potential):
                    # Transfering Pokemon
                    self.transfer_pokemon(pokemon_id)
                    logger.log(
                        '[#] {} has been exchanged for candy!'.format(
                            pokemon_name), 'green')
コード例 #8
0
ファイル: EvolveAll.py プロジェクト: Ipukema/PokeStats
    def _release_evolved(self, release_cand_list_ids):
        self.api.get_inventory()
        response_dict = self.api.call()
        cache = {}

        try:
            reduce(dict.__getitem__, [
                   "responses", "GET_INVENTORY", "inventory_delta", "inventory_items"], response_dict)
        except KeyError:
            pass
        else:
            release_cand_list = self._sort_by_cp(response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items'])
            release_cand_list = [x for x in release_cand_list if x[0] in release_cand_list_ids]

            ## at this point release_cand_list contains evolved pokemons data
            for cand in release_cand_list:
                pokemon_id = cand[0]
                pokemon_name = cand[1]
                pokemon_cp = cand[2]
                pokemon_potential = cand[3]

                if self.should_release_pokemon(pokemon_name, pokemon_cp, pokemon_potential):
                    # Transfering Pokemon
                    self.transfer_pokemon(pokemon_id)
                    logger.log(
                        '[#] {} has been exchanged for candy!'.format(pokemon_name), 'green')
コード例 #9
0
ファイル: pokecli.py プロジェクト: showcheap/PokemonGo-Bot
def main():
    # log settings
    # log format
    #logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(module)10s] [%(levelname)5s] %(message)s')

    sys.stdout = codecs.getwriter('utf8')(sys.stdout)
    sys.stderr = codecs.getwriter('utf8')(sys.stderr)

    config = init_config()
    if not config:
        return

    logger.log('[x] PokemonGO Bot v1.0', 'green')
    logger.log('[x] Configuration initialized', 'yellow')

    try:
        bot = PokemonGoBot(config)
        bot.start()

        logger.log('[x] Starting PokemonGo Bot....', 'green')

        while True:
            bot.take_step()

    except NotLoggedInException:
        logger.log('[x] Restarting PokemonGo Bot....', 'red')
        main()

    except KeyboardInterrupt:
        logger.log('[x] Exiting PokemonGo Bot', 'red')
コード例 #10
0
    def work(self):
        if not self.should_run():
            return

        forts = self.bot.get_forts(order_by_distance=True)

        if len(forts) == 0:
            logger.log('Found no forts to reset softban, skipping...', 'red')
            return
        logger.log('Got softban, fixing...', 'yellow')

        fort_distance = distance(
            self.bot.position[0],
            self.bot.position[1],
            forts[0]['latitude'],
            forts[0]['longitude'],
        )

        if fort_distance > Constants.MAX_DISTANCE_FORT_IS_REACHABLE:
            MoveToFort(self.bot, config=None).work()
            self.bot.recent_forts = self.bot.recent_forts[0:-1]
            if forts[0]['id'] in self.bot.fort_timeouts:
                del self.bot.fort_timeouts[forts[0]['id']]
            return WorkerResult.RUNNING
        else:
            spins = randint(50,60)
            logger.log('Starting %s spins...' % spins)
            for i in xrange(spins):
                if (i + 1) % 10 == 0:
                    logger.log('Spin #{}'.format(str(i+1)))
                self.spin_fort(forts[0])
            self.bot.softban = False
            logger.log('Softban should be fixed.')
コード例 #11
0
    def path(self, from_lat, form_lng, to_lat, to_lng):
        # type: (float, float, float, float) -> List[(float, float)]

        if self.config["debug"]:
            logger.log("[#] Asking google for directions")

        gmaps = googlemaps.Client(key=self.config["mapping"]["gmapkey"])

        now = datetime.now()
        start = "{},{}".format(from_lat, form_lng)
        end = "{},{}".format(to_lat, to_lng)
        directions_result = gmaps.directions(start, end, mode="walking", departure_time=now)

        if len(directions_result) and len(directions_result[0]["legs"]):
            steps = []
            for leg in directions_result[0]["legs"]:
                for step in leg["steps"]:
                    steps.append((step["end_location"]["lat"], step["end_location"]["lng"]))

            # Finally, walk to the stop's exact location as google can snap it's destinations to the
            # nearest road/path/address
            steps.append((to_lat, to_lng))

            return steps
        else:
            # If google doesn't know the way, then we just have to go as the crow flies
            return [
                (to_lat, to_lng)
            ]
コード例 #12
0
    def get_lured_pokemon(self):
        forts = self.bot.get_forts(order_by_distance=True)

        if len(forts) == 0:
            return False

        fort = forts[0]

        self.api.fort_details(fort_id=fort['id'],
                              latitude=fort['latitude'],
                              longitude=fort['longitude'])

        response_dict = self.api.call()
        fort_details = response_dict.get('responses', {}).get('FORT_DETAILS', {})
        fort_name = fort_details.get('name', 'Unknown').encode('utf8', 'replace')

        encounter_id = fort.get('lure_info', {}).get('encounter_id', None)

        if encounter_id:
            logger.log('Lured pokemon at fort {}'.format(fort['id']))
            return {
                'encounter_id': encounter_id,
                'fort_id': fort['id'],
                'latitude': fort['latitude'],
                'longitude': fort['longitude']
            }

        return False
コード例 #13
0
    def update_map_location(self):
        if not self.config['update_map']:
            return
        try:
            req = requests.get('{}/loc'.format(self.config['address']))
        except requests.exceptions.ConnectionError:
            logger.log('Could not reach PokemonGo-Map Server', 'red')
            return

        try:
            loc_json = req.json()
        except ValueError:
            return log.logger('Map location data was not valid', 'red')


        dist = distance(
            self.bot.position[0],
            self.bot.position[1],
            loc_json['lat'],
            loc_json['lng']
        )

        # update map when 500m away from center and last update longer than 2 minutes away
        now = int(time.time())
        if dist > 500 and now - self.last_map_update > 2 * 60:
            requests.post('{}/next_loc?lat={}&lon={}'.format(self.config['address'], self.bot.position[0], self.bot.position[1]))
            logger.log('Updated PokemonGo-Map position')
            self.last_map_update = now
コード例 #14
0
    def work(self):
        self.bot.latest_inventory = None
        item_count_dict = self.bot.item_inventory_count('all')

        for item_id, bag_count in item_count_dict.iteritems():
            item_name = self.bot.item_list[str(item_id)]
            id_filter = self.item_filter.get(item_name, 0)
            if id_filter is not 0:
                id_filter_keep = id_filter.get('keep', 20)
            else:
                id_filter = self.item_filter.get(str(item_id), 0)
                if id_filter is not 0:
                    id_filter_keep = id_filter.get('keep', 20)

            bag_count = self.bot.item_inventory_count(item_id)
            if (item_name in self.item_filter or str(item_id) in self.item_filter) and bag_count > id_filter_keep:
                items_recycle_count = bag_count - id_filter_keep
                response_dict_recycle = self.send_recycle_item_request(item_id=item_id, count=items_recycle_count)
                result = response_dict_recycle.get('responses', {}).get('RECYCLE_INVENTORY_ITEM', {}).get('result', 0)

                if result == 1: # Request success
                    message_template = "-- Discarded {}x {} (keeps only {} maximum) "
                    message = message_template.format(str(items_recycle_count), item_name, str(id_filter_keep))
                    logger.log(message, 'green')
                else:
                    logger.log("-- Failed to discard " + item_name, 'red')
コード例 #15
0
    def work(self):
        logger.log('[x] Initial Transfer.')
        ignlist = self.config.ign_init_trans.split(',')

        if self.config.cp:
            logger.log('[x] Will NOT transfer anything above CP {} or these {}'.format(
                self.config.cp, ignlist))
        else:
            logger.log('[x] Preparing to transfer all Pokemon duplicates, keeping the highest CP of each one type.')

        pokemon_groups = self._initial_transfer_get_groups()

        for group_id in pokemon_groups:

            group_cp = list(pokemon_groups[group_id].keys())

            if len(group_cp) > 1:
                group_cp.sort()
                group_cp.reverse()

                pokemon = self.pokemon_list[int(group_id - 1)]
                pokemon_name = pokemon['Name']
                pokemon_num = pokemon['Number'].lstrip('0')

                for i in range(1, len(group_cp)):

                    if (self.config.cp and group_cp[i] > self.config.cp) or (pokemon_name in ignlist or pokemon_num in ignlist):
                        continue

                    logger.log('[x] Transferring #{} ({}) with CP {}'.format(group_id, pokemon_name, group_cp[i]))
                    self.api_wrapper.release_pokemon(pokemon_id=pokemon_groups[group_id][group_cp[i]]).call()

                    sleep(2)

        logger.log('[x] Transferring Done.')
コード例 #16
0
 def release_pokemon(self, pokemon_name, cp, iv, pokemon_id):
     logger.log('Exchanging {} [CP {}] [Potential {}] for candy!'.format(pokemon_name,
                                                                         cp,
                                                                         iv), 'green')
     self.bot.api.release_pokemon(pokemon_id=pokemon_id)
     response_dict = self.bot.api.call()
     action_delay(self.bot.config.action_wait_min, self.bot.config.action_wait_max)
コード例 #17
0
ファイル: pokecli.py プロジェクト: Cryspart/PokemonGo-Bot
def main():
    # log settings
    # log format
    #logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(module)10s] [%(levelname)5s] %(message)s')

    sys.stdout = codecs.getwriter('utf8')(sys.stdout)
    sys.stderr = codecs.getwriter('utf8')(sys.stderr)

    config = init_config()
    if not config:
        return

    logger.log('[x] PokemonGO Bot v1.0', 'green')
    logger.log('[x] Configuration initialized', 'yellow')

    while True:
        try:
            bot = PokemonGoBot(config)
            bot.start()

            logger.log('[x] Starting PokemonGo Bot....', 'green')

            while True:
                bot.take_step()

        except KeyboardInterrupt:
            logger.log('[x] Exiting PokemonGo Bot', 'red')
            # TODO Add number of pokemon catched, pokestops visited, highest CP
            # pokemon catched, etc.
            break
        except:
            logger.log('[x] sleep 5s attempting to restart the bot', 'red')
            time.sleep(5)
コード例 #18
0
    def _validate_keep_best_config(self, pokemon_name):
        keep_best = False

        release_config = self._get_release_config_for(pokemon_name)

        keep_best_cp = release_config.get('keep_best_cp', 0)
        keep_best_iv = release_config.get('keep_best_iv', 0)

        if keep_best_cp or keep_best_iv:
            keep_best = True
            try:
                keep_best_cp = int(keep_best_cp)
            except ValueError:
                keep_best_cp = 0

            try:
                keep_best_iv = int(keep_best_iv)
            except ValueError:
                keep_best_iv = 0

            if keep_best_cp < 0 or keep_best_iv < 0:
                logger.log("Keep best can't be < 0. Ignore it.", "red")
                keep_best = False

            if keep_best_cp == 0 and keep_best_iv == 0:
                keep_best = False

        return keep_best, keep_best_cp, keep_best_iv
コード例 #19
0
 def _nickname_pokemon(self,pokemon):
     """This requies a pokemon object containing all the standard fields: id, ivs, cp, etc"""
     new_name = ""
     instance_id = pokemon.get('id',0)
     if not instance_id:
         logger.log("Pokemon instance id returned 0. Can't rename.",'red')
         return
     id = pokemon.get('pokemon_id',0)-1
     name = self.bot.pokemon_list[id]['Name']
     cp = pokemon.get('cp',0)
     iv_attack = pokemon.get('individual_attack',0)
     iv_defense = pokemon.get('individual_defense',0)
     iv_stamina = pokemon.get('individual_stamina',0)
     iv_list = [iv_attack,iv_defense,iv_stamina]
     iv_ads = "/".join(map(str,iv_list))
     iv_sum = sum(iv_list)
     iv_pct = "{:0.0f}".format(100*iv_sum/45.0)
     log_color = 'red'
     try:
         new_name = self.template.format(name=name,
                                 id=id,
                                 cp=cp,
                                 iv_attack=iv_attack,
                                 iv_defense=iv_defense,
                                 iv_stamina=iv_stamina,
                                 iv_ads=iv_ads,
                                 iv_sum=iv_sum,
                                 iv_pct=iv_pct)[:12]
     except KeyError as bad_key:
         logger.log("Unable to nickname {} due to bad template ({})".format(name,bad_key),log_color)
     if pokemon.get('nickname', "") == new_name:
         return
     self.bot.api.nickname_pokemon(pokemon_id=instance_id,nickname=new_name)
     response = self.bot.api.call()
     sleep(1.2)
     try: 
         result =  reduce(dict.__getitem__, ["responses", "NICKNAME_POKEMON"], response)
     except KeyError:
         logger.log("Attempt to nickname received bad response from server.",log_color)
         if self.bot.config.debug:
             logger.log(response,log_color)
         return
     result = result['result']
     if new_name == "":
         new_name = name
     output = {
         0: 'Nickname unset',
         1: 'Nickname set successfully! {} is now {}'.format(name,new_name),
         2: 'Invalid nickname! ({})'.format(new_name),
         3: 'Pokemon not found.',
         4: 'Pokemon is egg'
     }[result]
     if result==1:
         log_color='green'
         pokemon['nickname'] = new_name
     logger.log(output,log_color)
コード例 #20
0
ファイル: __init__.py プロジェクト: ch333/OpenPoGoBot
    def _init_plugins(self):
        # create a plugin manager
        self.plugin_manager = PluginManager('./plugins', log=logger)

        # load all plugin modules
        for plugin in self.plugin_manager.get_available_plugins():
            if plugin not in self.config.exclude_plugins:
                self.plugin_manager.load_plugin(plugin)
            else:
                logger.log("Not loading plugin \"{}\"".format(plugin))
コード例 #21
0
 def drop_excessive_items(self, item_id, item_name):
     # import pdb
     # pdb.set_trace()
     limit = self.config.item_limits.get(str(item_id))
     item_count = self.bot.item_inventory_count(item_id)
     if limit:
         drop_count = item_count - limit
         if drop_count > 0:
             self.bot.drop_item(item_id=item_id, count=item_count - limit)
             logger.log("[+] Auto-dropped " + str(drop_count) + " x " + item_name, 'green')
コード例 #22
0
 def _sleep(self):
     sleep_to_go = self._next_duration
     logger.log('It\'s time for sleep.')
     while sleep_to_go > 0:
         logger.log('Sleeping for {} more seconds'.format(sleep_to_go), 'yellow')
         if sleep_to_go < self.LOG_INTERVAL_SECONDS:
             sleep(sleep_to_go)
             sleep_to_go = 0
         else:
             sleep(self.LOG_INTERVAL_SECONDS)
             sleep_to_go -= self.LOG_INTERVAL_SECONDS
コード例 #23
0
ファイル: follow_path.py プロジェクト: avallete/PokemonGo-Bot
 def load_json(self):
     with open(self.path_file) as data_file:
         points=json.load(data_file)
     # Replace Verbal Location with lat&lng.
     logger.log("Resolving Navigation Paths (GeoLocating Strings)")
     for index, point in enumerate(points):
         if self.bot.config.debug:
             logger.log("Resolving Point {} - {}".format(index, point))
         point_tuple = self.bot.get_pos_by_name(point['location'])
         points[index] = self.lat_lng_tuple_to_dict(point_tuple)
     return points
コード例 #24
0
ファイル: uievents.py プロジェクト: AlexDevelop/OpenPoGoBot
    def client_ask_for_inventory_list():
        if "bot" in state:
            logger.log("Web UI action: Inventory List", "yellow", fire_event=False)
            bot = state["bot"]
            bot.api_wrapper.get_player().get_inventory()
            inventory = bot.api_wrapper.call()

            emit_object = {
                "inventory": inventory["inventory"]
            }
            socketio.emit("inventory_list", emit_object, namespace="/event", room=request.sid)
コード例 #25
0
    def _parse_get_hatched_eggs(self, key, response):
        if response.get("success", False):
            current_player = self.current_state.get("player", None)
            if current_player is None:
                current_player = Player()

            current_player.update_hatched_eggs(response)
            self._update_state({"player": current_player})

            if len(response.get("pokemon_id", [])) > 0:
                logger.log("[Egg] Hatched an egg!", "green")
                self.mark_returned_stale("GET_INVENTORY")
コード例 #26
0
 def work(self):
     self.bot.update_inventory()
     for item in self.bot.inventory:
         if str(item["item_id"]) in self.config.item_filter:
             amount_to_keep = self.config.item_filter.get(str(item["item_id"])).get("keep")
             if amount_to_keep is None:
                 continue
             amount_to_drop = item["count"] - amount_to_keep
             if amount_to_drop <= 0:
                 continue
             logger.log("[+] Recycling: {} x {}...".format(self.item_list[str(item["item_id"])], amount_to_drop), 'green')
             self.bot.drop_item(item["item_id"], amount_to_drop)
コード例 #27
0
    def work(self):
        forts = self.bot.get_forts()
        log_lure_avail_str = ''
        log_lured_str = ''
        if self.lured:
            log_lured_str = 'lured '
            lured_forts = [x for x in forts if 'lure_info' in x]
            if len(lured_forts) > 0:
                self.dest = find_biggest_cluster(self.radius, lured_forts, 'lure_info')
            else:
                log_lure_avail_str = 'No lured pokestops in vicinity. Search for normal ones instead. '
                self.dest = find_biggest_cluster(self.radius, forts)
        else:
            self.dest = find_biggest_cluster(self.radius, forts)

        if self.dest is not None:

            lat = self.dest['latitude']
            lng = self.dest['longitude']
            cnt = self.dest['num_points']

            if not self.is_at_destination:

                log_str = log_lure_avail_str + 'Move to destiny. ' + str(cnt) + ' ' + log_lured_str + \
                          'pokestops will be in range of ' + str(self.radius) + 'm. Arrive in ' \
                          + str(distance(self.bot.position[0], self.bot.position[1], lat, lng)) + 'm.'
                logger.log(log_str)
                self.announced = False

                if self.bot.config.walk > 0:
                    step_walker = StepWalker(
                        self.bot,
                        self.bot.config.walk,
                        lat,
                        lng
                    )

                    self.is_at_destination = False
                    if step_walker.step():
                        self.is_at_destination = True
                else:
                    self.bot.api.set_position(lat, lng)

            elif not self.announced:
                log_str = 'Arrived at destiny. ' + str(cnt) + ' pokestops are in range of ' \
                         + str(self.radius) + 'm.'
                logger.log(log_str)
                self.announced = True
        else:
            lat = self.bot.position[0]
            lng = self.bot.position[1]

        return [lat, lng]
コード例 #28
0
ファイル: pokecli.py プロジェクト: ryc111/PokemonGo-Bot
def print_all_iv(pokemon, pokemon_name ,pokemon_cp):
    pd = pokemon['inventory_item_data']['pokemon_data']
    ivs, iva, ivd = 0, 0, 0
    if ('individual_stamina' in pd):
        ivs = pd['individual_stamina']
    if ('individual_attack' in pd):
        iva = pd['individual_attack']
    if ('individual_defense' in pd):
        ivd = pd['individual_defense']
    pokemon_potential = round(((ivs+iva+ivd) / 45.0), 2)
    logger.log('[#] [Name/Stamina/Attack/Defense/CP/Potential] = /{}/{}/{}/{}/{}/{}/'.format(
        pokemon_name, ivs, iva, ivd, pokemon_cp, pokemon_potential))
コード例 #29
0
ファイル: bot_event.py プロジェクト: kmcgaire/PokemonGoBot
 def __init__(self,bot):
     self.bot = bot
     # UniversalAnalytics can be reviewed here:
     # https://github.com/analytics-pros/universal-analytics-python
     # For central TensorFlow training, forbiden any personally information
     # report to server
     # Review Very Carefully for the following line, forbiden ID changed PR:
     if bot.config.health_record:
         logger.log('Send anonymous bot health report to server, it can be disabled by config \"health_record\":false in config file', 'red')
         logger.log('Wait for 2 seconds ', 'red')
         sleep(3)
         self.tracker = Tracker.create('UA-81469507-1', use_post=True)
コード例 #30
0
    def _parse_get_hatched_eggs(self, key, response):
        if response.get("success", False):
            current_player = self.current_state.get("player", None)
            if current_player is None:
                current_player = Player()

            current_player.update_hatched_eggs(response)
            self._update_state({"player": current_player})

            if len(response.get("pokemon_id", [])) > 0:
                logger.log("[Egg] Hatched an egg!", "green")
                self.mark_returned_stale("GET_INVENTORY")
コード例 #31
0
    def call(self, max_retry=15):
        request_callers = self._pop_request_callers()
        if not self.can_call():
            return False # currently this is never ran, exceptions are raised before

        request_timestamp = None
        api_req_method_list = self._req_method_list
        result = None
        try_cnt = 0
        throttling_retry = 0
        unexpected_response_retry = 0
        while True:
            request_timestamp = self.throttle_sleep()
            # self._call internally clear this field, so save it
            self._req_method_list = [req_method for req_method in api_req_method_list]
            try:
                result = self._call()
                should_throttle_retry = False
                should_unexpected_response_retry = False
            except ServerSideRequestThrottlingException:
                should_throttle_retry = True
            except UnexpectedResponseException:
                should_unexpected_response_retry = True

            if should_throttle_retry:
                throttling_retry += 1
                if throttling_retry >= max_retry:
                    raise ServerSideRequestThrottlingException('Server throttled too many times')
                sleep(1) # huge sleep ?
                continue # skip response checking

            if should_unexpected_response_retry:
                unexpected_reponse_retry += 1
                if unexpected_response_retry >= 5:
                    logger.log('Server is not responding correctly to our requests.  Waiting for 30 seconds to reconnect.', 'red')
                    sleep(30)
                else:
                    sleep(2)
                continue
                
            if not self.is_response_valid(result, request_callers):
                try_cnt += 1
                if try_cnt > 3:
                    logger.log('Server seems to be busy or offline - try again - {}/{}'.format(try_cnt, max_retry), 'red')
                if try_cnt >= max_retry:
                    raise ServerBusyOrOfflineException()
                sleep(1)
            else:
                break

        self.last_api_request_time = request_timestamp
        return result
コード例 #32
0
ファイル: uievents.py プロジェクト: AlexDevelop/OpenPoGoBot
    def client_ask_for_pokemon_list():
        if "bot" in state:
            logger.log("Web UI action: Pokemon List", "yellow", fire_event=False)
            bot = state["bot"]
            bot.api_wrapper.get_player().get_inventory()
            inventory = bot.api_wrapper.call()

            emit_object = {
                "pokemon": inventory["pokemon"],
                "candy": inventory["candy"],
                "eggs_count": len(inventory["eggs"])
            }
            socketio.emit("pokemon_list", emit_object, namespace="/event", room=request.sid)
コード例 #33
0
 def work(self):
     response = self.bot.update_player_and_inventory()
     inventory = response["inventory"]
     for item in inventory:
         if item in self.config.item_filter:
             amount_to_keep = self.config.item_filter.get(item).get("keep")
             if amount_to_keep is None:
                 continue
             amount_to_drop = inventory[item] - amount_to_keep
             if amount_to_drop <= 0:
                 continue
             logger.log("[+] Recycling: {} x {}...".format(self.item_list[item], amount_to_drop), 'green')
             self.bot.drop_item(item, amount_to_drop)
コード例 #34
0
ファイル: uievents.py プロジェクト: AlexDevelop/OpenPoGoBot
    def client_ask_for_eggs_list():
        if "bot" in state:
            logger.log("Web UI action: Eggs List", "yellow", fire_event=False)
            bot = state["bot"]
            bot.api_wrapper.get_player().get_inventory()
            inventory = bot.api_wrapper.call()

            emit_object = {
                "km_walked": inventory["player"].km_walked,
                "eggs": inventory["eggs"],
                "egg_incubators": inventory["egg_incubators"]
            }
            socketio.emit("eggs_list", emit_object, namespace="/event", room=request.sid)
コード例 #35
0
ファイル: pokecli.py プロジェクト: Ipukema/PokemonGo-Bot-2
def main():
    # log settings
    # log format
    #logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(module)10s] [%(levelname)5s] %(message)s')

    sys.stdout = codecs.getwriter('utf8')(sys.stdout)
    sys.stderr = codecs.getwriter('utf8')(sys.stderr)

    config = init_config()
    if not config:
        return

    logger.log('[x] PokemonGO Bot v1.0', 'green')
    logger.log('[x] Configuration initialized', 'yellow')

    try:
        bot = PokemonGoBot(config)
        bot.start()

        logger.log('[x] Starting PokemonGo Bot....', 'green')

        while True:
            bot.take_step()

    except KeyboardInterrupt:
        logger.log('[x] Exiting PokemonGo Bot', 'red')
コード例 #36
0
    def work(self):
        logger.log('[x] Initial Transfer.')

        logger.log(
            '[x] Preparing to transfer all duplicate Pokemon, keeping the highest CP of each type.'
        )

        logger.log('[x] Will NOT transfer anything above CP {}'.format(
            self.config.initial_transfer))

        pokemon_groups = self._initial_transfer_get_groups()

        for id in pokemon_groups:

            group_cp = pokemon_groups[id].keys()

            if len(group_cp) > 1:
                group_cp.sort()
                group_cp.reverse()

                for x in range(1, len(group_cp)):
                    if self.config.initial_transfer and group_cp[
                            x] > self.config.initial_transfer:
                        continue

                    print('[x] Transferring {} with CP {}'.format(
                        self.pokemon_list[id - 1]['Name'], group_cp[x]))
                    self.api.release_pokemon(
                        pokemon_id=pokemon_groups[id][group_cp[x]])
                    response_dict = self.api.call()
                    sleep(2)

        logger.log('[x] Transferring Done.')
コード例 #37
0
    def navigate(self, map_cells):
        # type: (List[Cell]) -> None
        try:
            camp_site = self.camping_sites[self.pointer]

            lat, lng = camp_site
            position = (lat, lng, 0.0)

            yield Destination(*position,
                              name="camping position at {},{}".format(
                                  lat, lng),
                              exact_location=True)

            sleep(5)

        except KeyError:
            logger.log("[#] No campsite location found", color="red")
コード例 #38
0
ファイル: __init__.py プロジェクト: tegob/OpenPoGoBot
    def _get_pos_by_name(self, location_name):
        # type: (str) -> Tuple[float, float, float]
        if location_name.count(',') == 1:
            try:
                logger.log("[x] Fetching altitude from google")
                parts = location_name.split(',')

                pos_lat = float(parts[0])
                pos_lng = float(parts[1])

                # we need to ask google for the altitude
                gmaps = googlemaps.Client(key=self.config.gmapkey)
                response = gmaps.elevation((pos_lat, pos_lng))

                if len(response) and "elevation" in response[0]:
                    return pos_lat, pos_lng, response[0]["elevation"]
                else:
                    raise ValueError
            except ApiError:
                logger.log("[x] Could not fetch altitude from google. Trying geolocator.")
            except ValueError:
                logger.log("[x] Location was not Lat/Lng.")

        # Fallback to geolocation if no Lat/Lng can be found
        geolocator = GoogleV3(api_key=self.config.gmapkey)
        loc = geolocator.geocode(location_name, timeout=10)

        # self.log.info('Your given location: %s', loc.address.encode('utf-8'))
        # self.log.info('lat/long/alt: %s %s %s', loc.latitude, loc.longitude, loc.altitude)

        return loc.latitude, loc.longitude, loc.altitude
コード例 #39
0
    def work(self):
        lat = self.fort['latitude']
        lng = self.fort['longitude']
        fortID = self.fort['id']
        unit = self.config.distance_unit  # Unit to use when printing formatted distance

        dist = distance(self.position[0], self.position[1], lat, lng)

        # print('[#] Found fort {} at distance {}m'.format(fortID, dist))
        logger.log('[#] Found fort {} at distance {}'.format(
            fortID, format_dist(dist, unit)))

        if dist > 10:
            logger.log('[#] Need to move closer to Pokestop')
            position = (lat, lng, 0.0)

            if self.config.walk > 0:
                self.stepper._walk_to(self.config.walk, *position)
            else:
                self.api.set_position(*position)

            self.api.player_update(latitude=lat, longitude=lng)
            response_dict = self.api.call()
            logger.log('[#] Arrived at Pokestop')
            sleep(2)
            return response_dict

        return None
コード例 #40
0
ファイル: __init__.py プロジェクト: tegob/OpenPoGoBot
    def _init_plugins(self):
        # create a plugin manager
        self.plugin_manager = PluginManager('./plugins')

        # load all plugin modules
        for plugin in self.plugin_manager.get_available_plugins():
            if plugin not in self.config.exclude_plugins:
                self.plugin_manager.load_plugin(plugin)
            else:
                logger.log("Not loading plugin \"{}\"".format(plugin), color="red", prefix="Plugins")

        loaded_plugins = sorted(self.plugin_manager.get_loaded_plugins().keys())
        sleep(2)
        logger.log("Plugins loaded: {}".format(loaded_plugins), color="green", prefix="Plugins")
        logger.log("Events available: {}".format(manager.get_registered_events()), color="green", prefix="Events")
コード例 #41
0
ファイル: __init__.py プロジェクト: tegob/OpenPoGoBot
    def _set_starting_position(self):

        if self.config.test:
            return

        if self.config.location_cache:
            try:
                #
                # save location flag used to pull the last known location from
                # the location.json
                with open('data/last-location-%s.json' % self.config.username) as last_location_file:
                    location_json = json.load(last_location_file)

                    self.position = (location_json['lat'], location_json['lng'], 0.0)
                    self.api_wrapper.set_position(*self.position)

                    logger.log('')
                    logger.log('[x] Last location flag used. Overriding passed in location')
                    logger.log('[x] Last in-game location was set as: {}'.format(self.position))
                    logger.log('')

                    return
            except IOError:
                if not self.config.location:
                    sys.exit("No cached Location. Please specify initial location.")
                else:
                    self._read_config_location()
        else:
            self._read_config_location()

        logger.log('[x] Position in-game set as: {}'.format(self.position))
        logger.log('')
コード例 #42
0
ファイル: __init__.py プロジェクト: tegob/OpenPoGoBot
 def _read_config_location(self):
     self.position = self._get_pos_by_name(self.config.location)
     self.api_wrapper.set_position(*self.position)
     logger.log('')
     logger.log(u'[x] Address found: {}'.format(self.config.location))
コード例 #43
0
 def connect():
     socketio.emit("logging", logging_buffer, namespace="/event")
     logger.log("Web client connected", "yellow", fire_event=False)
コード例 #44
0
 def log(text, color=None):
     logger.log(text, color=color, prefix="Recycler")
コード例 #45
0
 def log(text, color="black"):
     logger.log(text, color=color, prefix="Transfer")
コード例 #46
0
    def work(self):
        lat = self.fort['latitude']
        lng = self.fort['longitude']

        self.api.fort_details(fort_id=self.fort['id'],
                              latitude=lat,
                              longitude=lng)
        response_dict = self.api.call()
        if 'responses' in response_dict \
                and'FORT_DETAILS' in response_dict['responses'] \
                and 'name' in response_dict['responses']['FORT_DETAILS']:
            fort_details = response_dict['responses']['FORT_DETAILS']
            fort_name = fort_details['name'].encode('utf8', 'replace')
        else:
            fort_name = 'Unknown'
        logger.log('[#] Now at Pokestop: ' + fort_name + ' - Spinning...',
                   'yellow')
        sleep(2)
        self.api.fort_search(fort_id=self.fort['id'],
                             fort_latitude=lat,
                             fort_longitude=lng,
                             player_latitude=f2i(self.position[0]),
                             player_longitude=f2i(self.position[1]))
        response_dict = self.api.call()
        if 'responses' in response_dict and \
                'FORT_SEARCH' in response_dict['responses']:

            spin_details = response_dict['responses']['FORT_SEARCH']
            if spin_details['result'] == 1:
                logger.log("[+] Loot: ", 'green')
                experience_awarded = spin_details.get('experience_awarded',
                                                      False)
                if experience_awarded:
                    logger.log("[+] " + str(experience_awarded) + " xp",
                               'green')

                items_awarded = spin_details.get('items_awarded', False)
                if items_awarded:
                    tmp_count_items = {}
                    for item in items_awarded:
                        item_id = item['item_id']
                        if not item_id in tmp_count_items:
                            tmp_count_items[item_id] = item['item_count']
                        else:
                            tmp_count_items[item_id] += item['item_count']

                    for item_id, item_count in tmp_count_items.iteritems():
                        item_name = self.item_list[str(item_id)]

                        logger.log(
                            "[+] " + str(item_count) + "x " + item_name +
                            " (Total: " +
                            str(self.bot.item_inventory_count(item_id)) + ")",
                            'green')

                        # RECYCLING UNWANTED ITEMS
                        if str(item_id) in self.config.item_filter:
                            logger.log(
                                "[+] Recycling " + str(item_count) + "x " +
                                item_name + "...", 'green')
                            #RECYCLE_INVENTORY_ITEM
                            response_dict_recycle = self.bot.drop_item(
                                item_id=item_id, count=item_count)

                            if response_dict_recycle and \
                                'responses' in response_dict_recycle and \
                                'RECYCLE_INVENTORY_ITEM' in response_dict_recycle['responses'] and \
                                    'result' in response_dict_recycle['responses']['RECYCLE_INVENTORY_ITEM']:
                                result = response_dict_recycle['responses'][
                                    'RECYCLE_INVENTORY_ITEM']['result']
                            if result is 1:  # Request success
                                logger.log("[+] Recycling success", 'green')
                            else:
                                logger.log("[+] Recycling failed!", 'red')
                else:
                    logger.log("[#] Nothing found.", 'yellow')

                pokestop_cooldown = spin_details.get(
                    'cooldown_complete_timestamp_ms')
                if pokestop_cooldown:
                    seconds_since_epoch = time.time()
                    logger.log('[#] PokeStop on cooldown. Time left: ' + str(
                        format_time((pokestop_cooldown / 1000) -
                                    seconds_since_epoch)))

                if not items_awarded and not experience_awarded and not pokestop_cooldown:
                    message = (
                        'Stopped at Pokestop and did not find experience, items '
                        'or information about the stop cooldown. You are '
                        'probably softbanned. Try to play on your phone, '
                        'if pokemons always ran away and you find nothing in '
                        'PokeStops you are indeed softbanned. Please try again '
                        'in a few hours.')
                    raise RuntimeError(message)
            elif spin_details['result'] == 2:
                logger.log("[#] Pokestop out of range")
            elif spin_details['result'] == 3:
                pokestop_cooldown = spin_details.get(
                    'cooldown_complete_timestamp_ms')
                if pokestop_cooldown:
                    seconds_since_epoch = time.time()
                    logger.log('[#] PokeStop on cooldown. Time left: ' + str(
                        format_time((pokestop_cooldown / 1000) -
                                    seconds_since_epoch)))
            elif spin_details['result'] == 4:
                print_red("[#] Inventory is full, switching to catch mode...")
                self.config.mode = 'poke'

            if 'chain_hack_sequence_number' in response_dict['responses'][
                    'FORT_SEARCH']:
                time.sleep(2)
                return response_dict['responses']['FORT_SEARCH'][
                    'chain_hack_sequence_number']
            else:
                print_yellow('[#] may search too often, lets have a rest')
                return 11
        sleep(8)
        return 0
コード例 #47
0
ファイル: __init__.py プロジェクト: tegob/OpenPoGoBot
 def log(text, color="black"):
     logger.log(text, color=color, prefix="Catch")
コード例 #48
0
ファイル: __init__.py プロジェクト: tegob/OpenPoGoBot
    def _setup_api(self):
        # instantiate api
        self.api_wrapper = PoGoApi(provider=self.config.auth_service, username=self.config.username,
                                   password=self.config.password)
        # provide player position on the earth

        self._set_starting_position()

        while not self.api_wrapper.login():
            logger.log('Login Error, server busy', 'red')
            logger.log('Waiting 15 seconds before trying again...')
            time.sleep(15)

        logger.log('[+] Login to Pokemon Go successful.', 'green')

        # chain subrequests (methods) into one RPC call

        # get player profile call
        # ----------------------
        response_dict = self.update_player_and_inventory()

        if response_dict is not None:
            player = response_dict['player']
            inventory = response_dict['inventory']
            pokemon = response_dict['pokemon']
            creation_date = player.get_creation_date()

            balls_stock = self.pokeball_inventory()

            pokecoins = player.pokecoin
            stardust = player.stardust

            logger.log('[#]')
            logger.log('[#] Username: {}'.format(player.username))
            logger.log('[#] Acccount Creation: {}'.format(creation_date))
            logger.log('[#] Bag Storage: {}/{}'.format(inventory["count"], player.max_item_storage))
            logger.log('[#] Pokemon Storage: {}/{}'.format(len(pokemon), player.max_pokemon_storage))
            logger.log('[#] Stardust: {}'.format(stardust))
            logger.log('[#] Pokecoins: {}'.format(pokecoins))
            logger.log('[#] PokeBalls: {}'.format(balls_stock[1]))
            logger.log('[#] GreatBalls: {}'.format(balls_stock[2]))
            logger.log('[#] UltraBalls: {}'.format(balls_stock[3]))
            logger.log('[#] -- Level: {}'.format(player.level))
            logger.log('[#] -- Experience: {}'.format(player.experience))
            logger.log('[#] -- Experience until next level: {}'.format(player.next_level_xp - player.experience))
            logger.log('[#] -- Pokemon Captured: {}'.format(player.pokemons_captured))
            logger.log('[#] -- Pokestops Visited: {}'.format(player.poke_stop_visits))
        # Testing
        # self.drop_item(Item.ITEM_POTION.value,1)
        # exit(0)

        if self.config.initial_transfer:
            self.fire("pokemon_bag_full")

        if self.config.recycle_items:
            self.fire("item_bag_full")

        logger.log('[#]')
        self.update_player_and_inventory()
コード例 #49
0
    def work(self):
        encounter_id = self.pokemon['encounter_id']
        spawnpoint_id = self.pokemon['spawnpoint_id']
        player_latitude = self.pokemon['latitude']
        player_longitude = self.pokemon['longitude']
        self.api.encounter(encounter_id=encounter_id,
                           spawnpoint_id=spawnpoint_id,
                           player_latitude=player_latitude,
                           player_longitude=player_longitude)
        response_dict = self.api.call()

        if response_dict and 'responses' in response_dict:
            if 'ENCOUNTER' in response_dict['responses']:
                if 'status' in response_dict['responses']['ENCOUNTER']:
                    if response_dict['responses']['ENCOUNTER']['status'] is 7:
                        logger.log('[x] Pokemon Bag is full!', 'red')
                        return PokemonCatchWorker.BAG_FULL

                    if response_dict['responses']['ENCOUNTER']['status'] is 1:
                        cp = 0
                        total_IV = 0
                        if 'wild_pokemon' in response_dict['responses'][
                                'ENCOUNTER']:
                            pokemon = response_dict['responses']['ENCOUNTER'][
                                'wild_pokemon']
                            catch_rate = response_dict['responses'][
                                'ENCOUNTER']['capture_probability'][
                                    'capture_probability']  # 0 = pokeballs, 1 great balls, 3 ultra balls

                            if 'pokemon_data' in pokemon and 'cp' in pokemon[
                                    'pokemon_data']:
                                cp = pokemon['pokemon_data']['cp']
                                iv_stats = [
                                    'individual_attack', 'individual_defense',
                                    'individual_stamina'
                                ]

                                for individual_stat in iv_stats:
                                    try:
                                        total_IV += pokemon['pokemon_data'][
                                            individual_stat]
                                    except:
                                        pokemon['pokemon_data'][
                                            individual_stat] = 0
                                        continue

                                pokemon_potential = round((total_IV / 45.0), 2)
                                pokemon_num = int(
                                    pokemon['pokemon_data']['pokemon_id']) - 1
                                pokemon_name = self.pokemon_list[int(
                                    pokemon_num)]['Name']
                                logger.log(
                                    '[#] A Wild {} appeared! [CP {}] [Potential {}]'
                                    .format(pokemon_name, cp,
                                            pokemon_potential), 'yellow')

                                logger.log(
                                    '[#] IV [Stamina/Attack/Defense] = [{}/{}/{}]'
                                    .format(
                                        pokemon['pokemon_data']
                                        ['individual_stamina'],
                                        pokemon['pokemon_data']
                                        ['individual_attack'],
                                        pokemon['pokemon_data']
                                        ['individual_defense']))
                                pokemon['pokemon_data']['name'] = pokemon_name
                                # Simulate app
                                sleep(3)

                        balls_stock = self.bot.pokeball_inventory()
                        while (True):

                            pokeball = 1  # default:poke ball

                            if balls_stock[
                                    1] <= 0:  # if poke ball are out of stock
                                if balls_stock[
                                        2] > 0:  # and player has great balls in stock...
                                    pokeball = 2  # then use great balls
                                elif balls_stock[
                                        3] > 0:  # or if great balls are out of stock too, and player has ultra balls...
                                    pokeball = 3  # then use ultra balls
                                else:
                                    pokeball = 0  # player doesn't have any of pokeballs, great balls or ultra balls

                            while (pokeball < 3):
                                if catch_rate[pokeball -
                                              1] < 0.35 and balls_stock[
                                                  pokeball + 1] > 0:
                                    # if current ball chance to catch is under 35%, and player has better ball - then use it
                                    pokeball = pokeball + 1  # use better ball
                                else:
                                    break

                            # @TODO, use the best ball in stock to catch VIP (Very Important Pokemon: Configurable)

                            if pokeball is 0:
                                logger.log(
                                    '[x] Out of pokeballs, switching to farming mode...',
                                    'red')
                                # Begin searching for pokestops.
                                self.config.mode = 'farm'
                                return PokemonCatchWorker.NO_POKEBALLS

                            balls_stock[pokeball] = balls_stock[pokeball] - 1
                            success_percentage = '{0:.2f}'.format(
                                catch_rate[pokeball - 1] * 100)
                            logger.log(
                                '[x] Using {} (chance: {}%)... ({} left!)'.
                                format(self.item_list[str(pokeball)],
                                       success_percentage,
                                       balls_stock[pokeball]))

                            id_list1 = self.count_pokemon_inventory()
                            self.api.catch_pokemon(
                                encounter_id=encounter_id,
                                pokeball=pokeball,
                                normalized_reticle_size=1.950,
                                spawn_point_guid=spawnpoint_id,
                                hit_pokemon=1,
                                spin_modifier=1,
                                NormalizedHitPosition=1)
                            response_dict = self.api.call()

                            if response_dict and \
                                'responses' in response_dict and \
                                'CATCH_POKEMON' in response_dict['responses'] and \
                                    'status' in response_dict['responses']['CATCH_POKEMON']:
                                status = response_dict['responses'][
                                    'CATCH_POKEMON']['status']
                                if status is 2:
                                    logger.log(
                                        '[-] Attempted to capture {}- failed.. trying again!'
                                        .format(pokemon_name), 'red')
                                    sleep(2)
                                    continue
                                if status is 3:
                                    logger.log(
                                        '[x] Oh no! {} vanished! :('.format(
                                            pokemon_name), 'red')
                                if status is 1:
                                    logger.log(
                                        '[x] Captured {}! [CP {}] [IV {}]'.
                                        format(pokemon_name, cp,
                                               pokemon_potential), 'green')

                                    id_list2 = self.count_pokemon_inventory()

                                    if self.config.evolve_captured:
                                        pokemon_to_transfer = list(
                                            Set(id_list2) - Set(id_list1))
                                        self.api.evolve_pokemon(
                                            pokemon_id=pokemon_to_transfer[0])
                                        response_dict = self.api.call()
                                        status = response_dict['responses'][
                                            'EVOLVE_POKEMON']['result']
                                        if status == 1:
                                            logger.log(
                                                '[#] {} has been evolved!'.
                                                format(pokemon_name), 'green')
                                        else:
                                            logger.log(
                                                '[x] Failed to evolve {}!'.
                                                format(pokemon_name))

                                    if self.should_release_pokemon(
                                            pokemon_name, cp,
                                            pokemon_potential, response_dict):
                                        # Transfering Pokemon
                                        pokemon_to_transfer = list(
                                            Set(id_list2) - Set(id_list1))
                                        if len(pokemon_to_transfer) == 0:
                                            raise RuntimeError(
                                                'Trying to transfer 0 pokemons!'
                                            )
                                        self.transfer_pokemon(
                                            pokemon_to_transfer[0])
                                        logger.log(
                                            '[#] {} has been exchanged for candy!'
                                            .format(pokemon_name), 'green')
                                    else:
                                        logger.log(
                                            '[x] Captured {}! [CP {}]'.format(
                                                pokemon_name, cp), 'green')
                            break
        time.sleep(5)
コード例 #50
0
 def disconnect():
     logger.log("Web client disconnected", "yellow", fire_event=False)
コード例 #51
0
ファイル: __init__.py プロジェクト: tegob/OpenPoGoBot
 def log(text, color="black"):
     logger.log(text, color=color, prefix="PokeStop")
コード例 #52
0
def log(text, color="black"):
    logger.log(text, color=color, prefix="Incubator")