Exemplo n.º 1
0
def main():
    # get token from command line
    if len(sys.argv) < 2:
        print("Usage: " + sys.argv[0] + ' <refresh_token>')
        exit()
    refresh_token = sys.argv[1]
    organization = None
    if len(sys.argv) > 2:
        organization = sys.argv[2]
    # swap token for an access token
    auth = Auth()
    access_token = auth.swap_refresh_token(refresh_token)

    # create a client and list the surveys that are available
    client = ThematicClient(access_token)

    surveys = client.surveys.get(organization=organization)
    print('Surveys:')
    for survey in surveys:
        print(str(survey["id"]) + " : " + survey['name'])
        print('\tVisualizations:')
        for vis in survey['visualizations']:
            print("\t" + str(vis["id"]) + " : " + vis['name'])
        print('\tResults:')
        for result in survey['results']:
            print("\t" + str(result['status']) + " : " + str(result['jobID']))
Exemplo n.º 2
0
def main():
    # get token and args from command line
    if len(sys.argv) < 3:
        print("Usage: "+sys.argv[0]+' <refresh_token> <survey_id> <output_format>')
        exit()
    refresh_token = sys.argv[1]
    survey_id = sys.argv[2]
    result_id = None
    output_format = None
    if len(sys.argv) > 3:
        output_format = sys.argv[3]
    # swap token for an access token
    auth = Auth()
    access_token = auth.swap_refresh_token(refresh_token)

    # create a client and upload the data
    client = ThematicClient(access_token)


    # get the processed file
    try:
        save_location = str(survey_id)+'_'+str(result_id)
        filename = save_location+'_processed.csv'
        print('saving data to {}'.format(filename))
        client.data.download_data(save_location+'_processed.csv',
                                  survey_id,
                                  result_id=result_id,
                                  output_format=output_format)
        filename = save_location+'_processed.json'
        print('saving data to {}'.format(filename))
        client.data.download_themes(filename, survey_id, result_id=result_id)
    except Exception as exc:
        print("Failed to get results: "+str(exc))
        exit()
Exemplo n.º 3
0
def main():
    # get token and args from command line
    if len(sys.argv) != 4:
        print("Usage: " + sys.argv[0] +
              ' <refresh_token> <survey_id> <data_file_path>')
        exit()
    refresh_token = sys.argv[1]
    survey_id = sys.argv[2]
    data_file = sys.argv[3]
    # swap token for an access token
    auth = Auth()
    access_token = auth.swap_refresh_token(refresh_token)

    # create a client and upload the data
    client = ThematicClient(access_token,
                            api_url='https://client.anz.getthematic.com/api')

    try:
        upload_id = client.data.upload_data(survey_id, data_file)
    except Exception as exc:
        print("Failed to upload data: " + str(exc))
        exit()

    # wait for the data to complete processing
    data = None
    while True:
        try:
            status = client.data.check_uploaded_data(survey_id, upload_id)
            if status == "ProcessingJobStatus.errored" or status == "ProcessingJobStatus.invalidated":
                print("Upload processing has failed with status: " + status)
                print("Retrieving logs...")
                logs = client.data.log_uploaded_data(survey_id, upload_id)
                print(logs)

            elif status == "ProcessingJobStatus.completed":
                print("Processing complete")
                break

        except Exception as exc:
            print("Failed to check status: " + str(exc))
            exit()
        time.sleep(2)

    # get the processed file
    try:
        save_location = data_file + 'processed.csv'
        client.data.download_upload_results(save_location, survey_id,
                                            upload_id)
    except Exception as exc:
        print("Failed to get results: " + str(exc))
        exit()