def get_owner_id(connection, screen_name, user=False):
    """Get the owner id of a user or group page.

    Parameters:
    -----------
    :connection:  vk_api.VkApi(...) instance, connection object;
    :screen_name: str, name of a user or group page we get from
                  a link (e.g. https://vk.com/azino777,
                  azino777 is the screen name);
    :user:        bool, True if it's a user page,
                  False if it's a group page;
    :returns:     int, the owner id
    """

    if user:
        user_objs = connection.method(
            'users.get',
            {'user_ids': screen_name}
        )
        return user_objs[0]['id']
    else:
        group_objs = connection.method(
            'groups.getById',
            {'group_id': screen_name}
        )
        # id must be negative if it's a group
        return group_objs[0]['id'] * (-1)