コード例 #1
0
ファイル: __init__.py プロジェクト: ch333/OpenPoGoBot
    def pokeball_inventory(self):
        self.api.get_player().get_inventory()

        inventory_req = self.api.call()
        inventory_list = convert_to_utf8(inventory_req['responses']['GET_INVENTORY']['inventory_delta']['inventory_items'])
        with open('web/inventory-{}.json'.format(self.config.username), 'w') as outfile:
            json.dump(inventory_list, outfile)

        # get player balls stock
        # ----------------------
        balls_stock = {Item.ITEM_POKE_BALL.value: 0,
                       Item.ITEM_GREAT_BALL.value: 0,
                       Item.ITEM_ULTRA_BALL.value: 0,
                       Item.ITEM_MASTER_BALL.value: 0}

        for item in inventory_list:
            item_data = item.get('inventory_item_data', {}).get('item')
            if item_data is None:
                continue
            if "item_id" in item_data and "count" in item_data:
                item_id = int(item_data['item_id'])
                item_count = int(item_data['count'])
                if item_id in balls_stock:
                    balls_stock[item_id] = item_count
        return balls_stock
コード例 #2
0
ファイル: stepper.py プロジェクト: RedSparr0w/OpenPoGoBot
    def _work_at_position(self, lat, lng, pokemon_only=False):
        cell_id = self._get_cell_id_from_latlong()
        timestamp = [0, ] * len(cell_id)
        self.api.get_map_objects(latitude=f2i(lat),
                                 longitude=f2i(lng),
                                 since_timestamp_ms=timestamp,
                                 cell_id=cell_id)

        response_dict = self.api.call()
        if response_dict is None:
            return
        # Passing data through last-location and location
        map_objects = response_dict.get("responses", {}).get("GET_MAP_OBJECTS")
        if map_objects is not None:
            with open("web/location-{}.json".format(self.config.username), "w") as outfile:
                json.dump({"lat": lat, "lng": lng, "cells": convert_to_utf8(map_objects.get("map_cells"))}, outfile)
            with open("data/last-location-{}.json".format(self.config.username), "w") as outfile:
                outfile.truncate()
                json.dump({"lat": lat, "lng": lng}, outfile)
            if "status" in map_objects:
                if map_objects.get("status") is 1:
                    map_cells = map_objects.get("map_cells")
                # Sort all by distance from current pos - eventually this should build graph and A* it
                map_cells.sort(key=lambda x: distance(lat, lng, x["forts"][0]["latitude"], x["forts"][0]["longitude"]) if "forts" in x and x["forts"] != [] else 1e6)
                for cell in map_cells:
                    self.bot.work_on_cell(cell, pokemon_only)
コード例 #3
0
ファイル: mapper.py プロジェクト: Ipukema/OpenPoGoBot
    def get_cells(self, lat, lng):
        # type: (float, float) -> List[Cell]
        cell_id = self._get_cell_id_from_latlong()
        timestamp = [0, ] * len(cell_id)
        self.api_wrapper.get_map_objects(latitude=f2i(lat),
                                         longitude=f2i(lng),
                                         since_timestamp_ms=timestamp,
                                         cell_id=cell_id)

        response_dict = self.api_wrapper.call()
        if response_dict is None:
            return
        # Passing data through last-location and location
        map_objects = response_dict["worldmap"]

        with open("web/location-{}.json".format(self.config.username), "w") as outfile:
            outfile.truncate()
            json.dump({"lat": lat, "lng": lng, "cells": convert_to_utf8(map_objects.cells)}, outfile)
        with open("data/last-location-{}.json".format(self.config.username), "w") as outfile:
            outfile.truncate()
            json.dump({"lat": lat, "lng": lng}, outfile)

        map_cells = map_objects.cells
        # Sort all by distance from current pos - eventually this should build graph and A* it
        map_cells.sort(key=lambda x: distance(lat, lng, x.pokestops[0].latitude, x.pokestops[0].longitude) if len(
            x.pokestops) > 0 else 1e6)

        return map_cells
コード例 #4
0
ファイル: logger.py プロジェクト: RedSparr0w/OpenPoGoBot
def log(string, color='black', fire_event=True):
    color_hex = {
        'green': '92m',
        'yellow': '93m',
        'red': '91m'
    }
    string = convert_to_utf8(string)
    if fire_event:
        manager.fire("logging", output=string, color=color)
    output = '[' + time.strftime("%Y-%m-%d %H:%M:%S") + '] ' + string
    if color in color_hex:
        output = "\033[" + color_hex[color] + output + "\033[0m"
    print(output)
    if LCD is not None and string is not None:
        LCD.message(string)
コード例 #5
0
ファイル: logger.py プロジェクト: superyetix/OpenPoGoBot
def log(string, color='black', fire_event=True):
    color_hex = {
        'green': '92m',
        'yellow': '93m',
        'red': '91m'
    }
    string = convert_to_utf8(string)
    if fire_event:
        manager.fire("logging", output=string, color=color)
    output = '[' + time.strftime("%Y-%m-%d %H:%M:%S") + '] ' + string
    if color in color_hex:
        output = "\033[" + color_hex[color] + output + "\033[0m"
    if platform.system() == "Windows":
        print(output.encode('cp437', errors='replace').decode('cp437'))
    else:
        print(output)
    if LCD is not None and string is not None:
        LCD.message(string)
コード例 #6
0
    def get_cells(self, lat, lng):
        # type: (float, float) -> List[Cell]
        cell_id = self._get_cell_id_from_latlong()
        timestamp = [
            0,
        ] * len(cell_id)
        self.api_wrapper.get_map_objects(latitude=f2i(lat),
                                         longitude=f2i(lng),
                                         since_timestamp_ms=timestamp,
                                         cell_id=cell_id)

        response_dict = self.api_wrapper.call()
        if response_dict is None:
            return
        # Passing data through last-location and location
        map_objects = response_dict["worldmap"]

        with open("web/location-{}.json".format(self.config.username),
                  "w") as outfile:
            outfile.truncate()
            json.dump(
                {
                    "lat": lat,
                    "lng": lng,
                    "cells": convert_to_utf8(map_objects.cells)
                }, outfile)
        with open("data/last-location-{}.json".format(self.config.username),
                  "w") as outfile:
            outfile.truncate()
            json.dump({"lat": lat, "lng": lng}, outfile)

        map_cells = map_objects.cells
        # Sort all by distance from current pos - eventually this should build graph and A* it
        map_cells.sort(key=lambda x: distance(lat, lng, x.pokestops[
            0].latitude, x.pokestops[0].longitude)
                       if len(x.pokestops) > 0 else 1e6)

        return map_cells