Exemplo n.º 1
0
def visit_near_pokestops(bot, pokestops=None):
    # type: (PokemonGoBot, Optional[List[Fort]]) -> Dict[Str, List[PokeStop]]

    def log(text, color="black"):
        logger.log(text, color=color, prefix="PokeStop")

    if pokestops is None:
        return

    # If we're debugging, don't filter pokestops so we can test if they are on cooldown
    if not bot.config.debug:
        pokestops = filtered_forts(bot.stepper.current_lat, bot.stepper.current_lng, pokestops)

    now = int(time.time()) * 1000
    for pokestop in pokestops:
        dist = distance(bot.stepper.current_lat, bot.stepper.current_lng, pokestop.latitude, pokestop.longitude)

        if dist < 15:
            if pokestop.cooldown_timestamp_ms < now:
                manager.fire_with_context("pokestop_arrived", bot, pokestop=pokestop)
            elif bot.config.debug:
                log(
                    "Nearby fort found is in cooldown for {} ({}m away)".format(
                        format_time((pokestop.cooldown_timestamp_ms - now) / 1000), ceil(dist)
                    ),
                    color="yellow",
                )
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
    def visit_near_pokestops(self, bot, pokestops=None):
        # type: (PokemonGoBot, Optional[List[Fort]]) -> Dict[Str, List[PokeStop]]

        if pokestops is None:
            return

        # If we're debugging, don't filter pokestops so we can test if they are on cooldown
        if not bot.config["debug"]:
            pokestops = filtered_forts(bot.stepper.current_lat,
                                       bot.stepper.current_lng, pokestops)

        now = int(time.time()) * 1000
        for pokestop in pokestops:
            dist = distance(bot.stepper.current_lat, bot.stepper.current_lng,
                            pokestop.latitude, pokestop.longitude)

            if dist < 35:
                if pokestop.is_in_cooldown() is False:
                    self.event_manager.fire_with_context('pokestop_arrived',
                                                         bot,
                                                         pokestop=pokestop)
                elif bot.config["debug"]:
                    self.log(
                        "Nearby fort found is in cooldown for {} ({}m away)".
                        format(
                            format_time(
                                (pokestop.cooldown_timestamp_ms - now) / 1000),
                            ceil(dist)),
                        color="yellow")
Exemplo n.º 4
0
    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()
Exemplo n.º 5
0
    def step(self, destination):
        # type: (Destination) -> List[(float, float, float)]
        dist = distance(self.current_lat, self.current_lng, destination.target_lat, destination.target_lng)

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

        for step in destination.step():
            if distance(self.current_lat, self.current_lng, destination.target_lat, destination.target_lng) < 30:
                break
            self._step_to(*step)
            yield step

        if destination.name:
            self.logger.log("Arrived at {} ({} away)".format(destination.name, format_dist(dist, self.config["mapping"]["distance_unit"])), prefix="Navigation")
Exemplo n.º 6
0
    def _walk_to(self, to_lat, to_lng, to_alt):
        # type: (float, float, float) -> None
        dist = distance(self.current_lat, self.current_lng, to_lat, to_lng)
        steps = (dist / (self.AVERAGE_STRIDE_LENGTH_IN_METRES * self.speed))

        if self.config.debug:
            logger.log("[#] Walking from " + str((self.current_lat, self.current_lng)) + " to " + str(
                str((to_lat, to_lng))) + " for approx. " + str(format_time(ceil(steps))))

        if steps != 0:
            d_lat = (to_lat - self.current_lat) / steps
            d_long = (to_lng - self.current_lng) / steps

            for _ in range(int(ceil(steps))):
                c_lat = self.current_lat + d_lat + random_lat_long_delta(10)
                c_long = self.current_lng + d_long + random_lat_long_delta(10)
                self._jump_to(c_lat, c_long, to_alt)

            self.bot.heartbeat()
Exemplo n.º 7
0
    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))
Exemplo n.º 8
0
def spin_pokestop(bot, pokestop=None):
    # type: (PokemonGoBot, Optional[List[Fort]]) -> None

    if pokestop is None:
        return

    def log(text, color="black"):
        logger.log(text, color=color, prefix="PokeStop")

    fort_id = pokestop.fort_id
    latitude = pokestop.latitude
    longitude = pokestop.longitude
    player_latitude = bot.stepper.current_lat
    player_longitude = bot.stepper.current_lng

    fort_details = bot.api_wrapper.fort_details(fort_id=pokestop.fort_id,
                                                latitude=pokestop.latitude,
                                                longitude=pokestop.longitude).call()
    dist = distance(bot.stepper.current_lat, bot.stepper.current_lng, pokestop.latitude, pokestop.longitude)
    log("Nearby PokeStop found \"{}\" ({} away)".format(fort_details["fort"].fort_name,
                                                        format_dist(dist, bot.config["mapping"]["distance_unit"])), color="yellow")

    log("Spinning...", color="yellow")
    sleep(3)
    bot.api_wrapper.fort_search(fort_id=fort_id,
                                fort_latitude=latitude,
                                fort_longitude=longitude,
                                player_latitude=player_latitude,
                                player_longitude=player_longitude)

    response = bot.api_wrapper.call()
    if response is None:
        log("Got empty response from the API. Skipping.", color="red")
        return

    # TODO: Fix this to use a response object
    spin_details = response["FORT_SEARCH"]
    spin_result = spin_details.get("result")
    if spin_result == 1:
        log("Loot: ", "green")

        manager.fire_with_context('pokestop_visited', bot, pokestop=pokestop)

        experience_awarded = spin_details.get("experience_awarded", False)
        if experience_awarded:
            log("+ {} XP".format(experience_awarded), "green")

        items_awarded = spin_details.get("items_awarded", [])
        if len(items_awarded) > 0:
            tmp_count_items = {}
            for item in items_awarded:
                item_id = item["item_id"]
                if item_id not 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.items():
                item_name = bot.item_list[item_id]

                log("+ {} {}{}".format(item_count, item_name, "s" if item_count > 1 else ""), "green")
        else:
            log("Nothing found.", "yellow")

        pokestop_cooldown = spin_details.get("cooldown_complete_timestamp_ms")
        if pokestop_cooldown:
            seconds_since_epoch = time.time()
            cooldown_time = str(format_time((pokestop_cooldown / 1000) - seconds_since_epoch))
            log("PokeStop is on cooldown for {}.".format(cooldown_time))

            # Update the cooldown manually
            pokestop.cooldown_timestamp_ms = pokestop_cooldown

        if not items_awarded and not experience_awarded and not pokestop_cooldown:
            log("Might be softbanned, try again later.", "red")
    elif spin_result == 2:
        log("PokeStop is out of range.", "red")
    elif spin_result == 3:
        log("PokeStop is already on cooldown.", "red")
        pokestop_cooldown = spin_details.get("cooldown_complete_timestamp_ms")
        if pokestop_cooldown:
            seconds_since_epoch = time.time()
            cooldown_time = str(format_time((pokestop_cooldown / 1000) - seconds_since_epoch))
            log("PokeStop is already on cooldown for {}.".format(cooldown_time), "red")
    elif spin_result == 4:
        manager.fire_with_context('pokestop_visited', bot, pokestop=pokestop)

        experience_awarded = spin_details.get("experience_awarded", False)
        if experience_awarded:
            log("Loot: ", "green")
            log("+ {} XP".format(experience_awarded), "green")

        log("Item bag is full.", "red")

        bot.fire("item_bag_full")

        if not experience_awarded and not pokestop_cooldown:
            log("Might be softbanned, try again later.", "red")
    else:
        log("I don't know what happened! Maybe servers are down?", "red")

    sleep(2)
Exemplo n.º 9
0
 def test_format_time():
     assert (format_time(0.123)) == "0.12 second"
     assert (format_time(12.345)) == "12.35 seconds"
     assert (format_time(123.456)) == "2.06 minutes"
     assert (format_time(123.456)) == "2.06 minutes"
     assert (format_time(12345.678)) == "12345.68 seconds"
Exemplo n.º 10
0
    def work(self):
        lat = self.fort["latitude"]
        lng = self.fort["longitude"]
        logger.log("Spinning...", "yellow")
        sleep(3)
        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 response_dict is None:
            return
        spin_details = response_dict.get("responses", {}).get("FORT_SEARCH", {})
        spin_result = spin_details.get("result")
        if spin_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 item_id not 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.items():
                    item_id = str(item_id)
                    item_name = self.item_list[item_id]

                    logger.log("[+] " + str(item_count) + "x " + item_name,
                               "green")
                if self.config.recycle_items:
                    recycle_worker = RecycleItemsWorker(self.bot)
                    recycle_worker.work()

            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_result == 2:
            logger.log("[#] Pokestop out of range")
        elif spin_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_result == 4:
            logger.log("[#] Inventory is full, switching to catch mode...", "red")
            self.config.mode = "poke"

        sleep(2)
Exemplo n.º 11
0
    def spin_pokestop(self, bot, pokestop=None):
        # type: (PokemonGoBot, Optional[List[Fort]]) -> None

        if pokestop is None:
            return

        fort_id = pokestop.fort_id
        latitude = pokestop.latitude
        longitude = pokestop.longitude
        player_latitude = bot.stepper.current_lat
        player_longitude = bot.stepper.current_lng

        fort_details = bot.api_wrapper.fort_details(
            fort_id=pokestop.fort_id,
            latitude=pokestop.latitude,
            longitude=pokestop.longitude).call()
        dist = distance(bot.stepper.current_lat, bot.stepper.current_lng,
                        pokestop.latitude, pokestop.longitude)
        self.log("Nearby PokeStop found \"{}\" ({} away)".format(
            fort_details["fort"].fort_name,
            format_dist(dist, bot.config["mapping"]["distance_unit"])),
                 color="yellow")

        self.log("Spinning...", color="yellow")
        sleep(3)
        bot.api_wrapper.fort_search(fort_id=fort_id,
                                    fort_latitude=latitude,
                                    fort_longitude=longitude,
                                    player_latitude=player_latitude,
                                    player_longitude=player_longitude)

        response = bot.api_wrapper.call()
        if response is None:
            self.log("Got empty response from the API. Skipping.", color="red")
            return

        # TODO: Fix this to use a response object
        spin_details = response["FORT_SEARCH"]
        spin_result = spin_details.get("result")
        if spin_result == 1:
            self.log("Loot: ", "green")

            self.event_manager.fire_with_context('pokestop_visited',
                                                 bot,
                                                 pokestop=pokestop)

            experience_awarded = spin_details.get("experience_awarded", False)
            if experience_awarded:
                self.log("+ {} XP".format(experience_awarded), "green")

            items_awarded = spin_details.get("items_awarded", [])
            if len(items_awarded) > 0:
                tmp_count_items = {}
                for item in items_awarded:
                    item_id = item["item_id"]
                    if item_id not 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.items():
                    item_name = bot.item_list[item_id]

                    self.log(
                        "+ {} {}{}".format(item_count, item_name,
                                           "s" if item_count > 1 else ""),
                        "green")
            else:
                self.log("Nothing found.", "yellow")

            pokestop_cooldown = spin_details.get(
                "cooldown_complete_timestamp_ms")
            if pokestop_cooldown:
                seconds_since_epoch = time.time()
                cooldown_time = str(
                    format_time((pokestop_cooldown / 1000) -
                                seconds_since_epoch))
                self.log(
                    "PokeStop is on cooldown for {}.".format(cooldown_time))

                # Update the cooldown manually
                pokestop.cooldown_timestamp_ms = pokestop_cooldown

            if not items_awarded and not experience_awarded and not pokestop_cooldown:
                self.log("Might be softbanned, try again later.", "red")
        elif spin_result == 2:
            self.log("PokeStop is out of range.", "red")
        elif spin_result == 3:
            self.log("PokeStop is already on cooldown.", "red")
            pokestop_cooldown = spin_details.get(
                "cooldown_complete_timestamp_ms")
            if pokestop_cooldown:
                seconds_since_epoch = time.time()
                cooldown_time = str(
                    format_time((pokestop_cooldown / 1000) -
                                seconds_since_epoch))
                self.log(
                    "PokeStop is already on cooldown for {}.".format(
                        cooldown_time), "red")
        elif spin_result == 4:
            self.event_manager.fire_with_context('pokestop_visited',
                                                 bot,
                                                 pokestop=pokestop)

            experience_awarded = spin_details.get("experience_awarded", False)
            if experience_awarded:
                self.log("Loot: ", "green")
                self.log("+ {} XP".format(experience_awarded), "green")

                self.log("Item bag is full.", "red")

            bot.fire("item_bag_full")

            if not experience_awarded and not pokestop_cooldown:
                self.log("Might be softbanned, try again later.", "red")
        else:
            self.log("I don't know what happened! Maybe servers are down?",
                     "red")

        sleep(2)
Exemplo n.º 12
0
    def walk_to(self, speed, lat, lng, alt):
        position_lat, position_lng, _ = self.api.get_position()
        dist = distance(i2f(position_lat), i2f(position_lng), lat, lng)
        steps = (dist / (self.AVERAGE_STRIDE_LENGTH_IN_METRES * speed))

        logger.log("[#] Walking from " + str((i2f(position_lat), i2f(position_lng))) + " to " + str(str((lat, lng))) + " for approx. " + str(format_time(ceil(steps))))
        if steps != 0:
            d_lat = (lat - i2f(position_lat)) / steps
            d_long = (lng - i2f(position_lng)) / steps

            for _ in range(int(steps)):
                position_lat, position_lng, _ = self.api.get_position()
                c_lat = i2f(position_lat) + d_lat + random_lat_long_delta()
                c_long = i2f(position_lng) + d_long + random_lat_long_delta()
                self.api.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.get_position()
                self._work_at_position(i2f(position_lat), i2f(position_lng), False)

            self.bot.heartbeat()
            logger.log("[#] Finished walking")