def main(api_endpoint):
    email = input('Enter email: ')
    password = getpass.getpass()
    project_id = input('Enter project id: ')

    with open('./conf/new_assets.yml', 'r') as f:
        configuration = yaml.safe_load(f)

    assets = configuration['assets']

    client, user_id = authenticate(email, password, api_endpoint)

    for asset in tqdm(assets):
        external_id = get(asset, 'externalId')
        json_metadata = json.loads(get(asset, 'metadata'))
        assets = get_assets_by_external_id(client, project_id, external_id)
        assert len(assets) == 1
        asset_id = assets[0]['id']
        update_properties_in_asset(client,
                                   asset_id,
                                   json_metadata=json_metadata)
email = input('Enter email: ')
password = getpass.getpass()
project_id = input('Enter project id: ')

MAX_NUMBER_OF_ASSET = 50

path_gz = download_dataset()
path_dir = extract_dataset(path_gz)

only_files = [
    os.path.join(path, name) for path, subdirs, files in os.walk(path_dir)
    for name in files
]

client, user_id = authenticate(email, password)

for filepath in tqdm(only_files[:MAX_NUMBER_OF_ASSET]):
    with open(filepath, 'r') as f:
        content = f.read()
    external_id = filepath
    # Insert asset
    append_to_dataset(client, project_id, escape_content(content), external_id)
    asset = get_assets_by_external_id(client, project_id, external_id)
    asset_id = asset[0]['id']

    # Prioritize assets
    update_properties_in_asset(client, asset_id, priority=1)

    # Insert pre-annotations
    response = analyze_entities(content)
def execute_mutations(configuration_file, graphql_client):
    """
    Read configuration file (YAML) and execute mutations accordingly
    """

    with open(configuration_file, 'r') as f:
        configuration = yaml.safe_load(f)

    for mutation_name in tqdm(configuration['mutations']):

        organization = get(configuration, 'organization')
        projects = get(configuration, 'projects')
        users = get(configuration, 'users')
        tools = get(configuration, 'tools')
        authentication = get(configuration, 'authentication')

        if 'createOrganization' in mutation_name:
            if 'id' in organization:
                configuration['organization'] = organization
                continue
            args = ['name', 'address', 'zip_code', 'city', 'country']
            values = [get(organization, a) for a in args]
            configuration['organization'] = create_organization(
                client, *values)

        if 'createUser' in mutation_name or 'getUser' in mutation_name:
            for i, user in enumerate(users):
                if is_blacklisted(user['email']):
                    continue
                args = ['name', 'email', 'password', 'phone']
                values = [get(user, a) for a in args]
                organization_id = organization['id']
                organization_role = 'USER'
                user = create_user(client, *values, organization_id,
                                   organization_role)
                configuration['users'][i]['id'] = user['id']

        if 'createEmptyProject' in mutation_name:
            user_id = authentication['user']['id']
            for i, project in enumerate(projects):
                project = create_empty_project(client, user_id)
                configuration['projects'][i]['id'] = project['id']

        if 'updateProject' in mutation_name or 'deleteProject' in mutation_name:
            for i, project in enumerate(projects):
                args = ['id', 'title', 'description', 'interface_category']
                values = [get(project, a) for a in args]
                update_project(client, *values)

        if 'appendToTools' in mutation_name:
            for i, project in enumerate(projects):
                for j, tool in enumerate(tools):
                    if i == j:
                        project_id = project['id']
                        args = ['name', 'type']
                        values = [get(tool, a) for a in args]
                        json_settings = json.loads(get(tool, 'json_settings'))
                        append_to_tools(client,
                                        project_id,
                                        *values,
                                        json_settings=json_settings)

        if 'appendToRoles' in mutation_name:
            for i, project in enumerate(projects):
                for user in users:
                    project_id = project['id']
                    args = ['email', 'role']
                    values = [get(user, a) for a in args]
                    append_to_roles(client, project_id, *values)

        if 'getProjects' in mutation_name:
            user = authentication['user']
            get_projects(client, user_id=user['id'])

        if 'signIn' in mutation_name:
            email = get(authentication, 'email')
            password = getpass.getpass(f'Enter password for user "{email}":')
            client, user_id = authenticate(email, password, graphql_client)
            authentication['user'] = {'id': user_id}