Example #1
0
def main():
    # log settings
    # log format
    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(module)10s] [%(levelname)5s] %(message)s')
    # log level for http request class
    logging.getLogger("requests").setLevel(logging.WARNING)
    # log level for main pgoapi class
    logging.getLogger("pgoapi").setLevel(logging.INFO)
    # log level for internal pgoapi class
    logging.getLogger("rpc_api").setLevel(logging.INFO)

    config = init_config()
    if not config:
        return

    if config.debug:
        logging.getLogger("requests").setLevel(logging.DEBUG)
        logging.getLogger("pgoapi").setLevel(logging.DEBUG)
        logging.getLogger("rpc_api").setLevel(logging.DEBUG)

    position = get_pos_by_name(config.location)
    if config.test:
        return

    # instantiate pgoapi
    api = PGoApi()
    # provide player position on the earth
    api.set_position(*position)
    print(position)

    if not api.login(config.auth_service, config.username, config.password):
        return

    # chain subrequests (methods) into one RPC call

    # get player profile call
    # ----------------------
    api.get_player()

    response_dict = api.call()
    #print('Response dictionary: \n\r{}'.format(json.dumps(response_dict, indent=2)))
    currency_1="0"
    currency_2="0"
    if 'amount' in response_dict['responses']['GET_PLAYER']['profile']['currency'][0]:
        currency_1=response_dict['responses']['GET_PLAYER']['profile']['currency'][0]['amount']
    if 'amount' in response_dict['responses']['GET_PLAYER']['profile']['currency'][1]:
        currency_2=response_dict['responses']['GET_PLAYER']['profile']['currency'][1]['amount']
    print 'Profile:'
    print '    Username: '******'responses']['GET_PLAYER']['profile']['username'])
    print '    Bag size: ' + str(response_dict['responses']['GET_PLAYER']['profile']['item_storage'])
    print '    Pokemon Storage Size: ' + str(response_dict['responses']['GET_PLAYER']['profile']['poke_storage'])
    print '    Account Creation: ' + str(response_dict['responses']['GET_PLAYER']['profile']['creation_time'])
    print '    Currency: '
    print '        ' + str(response_dict['responses']['GET_PLAYER']['profile']['currency'][0]['type']) + ': ' + str(currency_1)
    print '        ' + str(response_dict['responses']['GET_PLAYER']['profile']['currency'][1]['type']) + ': ' + str(currency_2)

    #working.transfer_low_cp_pokomon(api,50)

    pos = 1
    x = 0
    y = 0
    dx = 0
    dy = -1
    steplimit=10
    steplimit2 = steplimit**2
    origin_lat=position[0]
    origin_lon=position[1]
    while(True):
        for step in range(steplimit2):
            #starting at 0 index
            print('looping: step {} of {}'.format((step+1), steplimit**2))
            print('steplimit: {} x: {} y: {} pos: {} dx: {} dy {}'.format(steplimit2, x, y, pos, dx, dy))
            # Scan location math
            if -steplimit2 / 2 < x <= steplimit2 / 2 and -steplimit2 / 2 < y <= steplimit2 / 2:
                position=(x * 0.0025 + origin_lat, y * 0.0025 + origin_lon, 0)
                if config.walk > 0:
                    api.walk(config.walk, *position)
                else:
                    api.set_position(*position)
                print(position)
            if x == y or x < 0 and x == -y or x > 0 and x == 1 - y:
                (dx, dy) = (-dy, dx)

            (x, y) = (x + dx, y + dy)
            # get map objects call
            # ----------------------
            timestamp = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
            cellid = get_cellid(position[0], position[1])
            api.get_map_objects(latitude=f2i(position[0]), longitude=f2i(position[1]), since_timestamp_ms=timestamp, cell_id=cellid)

            response_dict = api.call()
            #print('Response dictionary: \n\r{}'.format(json.dumps(response_dict, indent=2)))
            if response_dict and 'responses' in response_dict and \
                'GET_MAP_OBJECTS' in response_dict['responses'] and \
                'status' in response_dict['responses']['GET_MAP_OBJECTS'] and \
                response_dict['responses']['GET_MAP_OBJECTS']['status'] is 1:
                #print('got the maps')
                map_cells=response_dict['responses']['GET_MAP_OBJECTS']['map_cells']
                #print('map_cells are {}'.format(len(map_cells)))
                for cell in map_cells:
                    working.work_on_cell(cell,api,position,config)
            time.sleep(10)