luminoso_api/v4_upload.py
def upload_stream(stream, server, account, projname, language=None,
                  username=None, password=None,
                  append=False, stage=False):
    """
    Given a file-like object containing a JSON stream, upload it to
    Luminoso with the given account name and project name.
    """
    client = LuminosoClient.connect(server,
                                    username=username, password=password)
    if not append:
        # If we're not appending to an existing project, create new project.
        info = client.post('/projects/' + account, name=projname)
        project_id = info['project_id']
        print('New project ID:', project_id)
    else:
        projects = client.get('/projects/' + account, name=projname)
        if len(projects) == 0:
            print('No such project exists!')
            return
        if len(projects) > 1:
            print('Warning: Multiple projects with name "%s".  ' % projname,
                  end='')
        project_id = projects[0]['project_id']
        print('Using existing project with id %s.' % project_id)

    project = client.change_path('/projects/' + account + '/' + project_id)

    counter = 0
    for batch in batches(stream, 1000):
        counter += 1
        documents = list(batch)
        project.upload('docs', documents)
        print('Uploaded batch #%d' % (counter))

    if not stage:
        # Calculate the docs into the assoc space.
        print('Calculating.')
        kwargs = {}
        if language is not None:
            kwargs = {'language': language}
        job_id = project.post('docs/recalculate', **kwargs)
        project.wait_for(job_id)
def upload_stream(stream, server, account, projname, language=None,
                  username=None, password=None,
                  append=False, stage=False):
    """
    Given a file-like object containing a JSON stream, upload it to
    Luminoso with the given account name and project name.
    """
    client = LuminosoClient.connect(server,
                                    username=username, password=password)
    if not append:
        # If we're not appending to an existing project, create new project.
        info = client.post('/projects/' + account, name=projname)
        project_id = info['project_id']
        print('New project ID:', project_id)
    else:
        projects = client.get('/projects/' + account, name=projname)
        if len(projects) == 0:
            print('No such project exists!')
            return
        if len(projects) > 1:
            print('Warning: Multiple projects with name "%s".  ' % projname,
                  end='')
        project_id = projects[0]['project_id']
        print('Using existing project with id %s.' % project_id)

    project = client.change_path('/projects/' + account + '/' + project_id)

    counter = 0
    for batch in batches(stream, 1000):
        counter += 1
        documents = list(batch)
        project.upload('docs', documents)
        print('Uploaded batch #%d' % (counter))

    if not stage:
        # Calculate the docs into the assoc space.
        print('Calculating.')
        kwargs = {}
        if language is not None:
            kwargs = {'language': language}
        job_id = project.post('docs/recalculate', **kwargs)
        project.wait_for(job_id)
Given a file-like object containing a JSON stream, upload it to
    Luminoso with the given account name and project name.