def get_project_list_data():
    log.info('In Project List Data ----')
    data = dict()
    project_list = dict()
    try:
        projects = get_distinct_projects()

        for (project) in projects:
            project_list[project[0]] = project[0]

        log_output('PROJECT LIST')
        log_output(project_list)
        for (project) in project_list:
            log.info('INSIDE LOOP')
            # Request an access token from the metadata server.
            token_data = get_access_token()
            resp_access = token_data['resp_access']
            content_access = token_data['content_access']

            if resp_access.status == 200:

                # Extract the access token from the response.
                d = json.loads(content_access)
                access_token = d['access_token']  # Save the access token
                # log.debug('access_token -- {0}'.format(access_token))
                # Construct the request to Google Cloud Storage
                if project != 'Not Available':
                    project_id = project.split('-')[1]
                else:
                    project_id = 'Not Available'

                project_data = get_project_data(project_id, access_token)
                resp = project_data['resp']
                content = project_data['content']
                if resp.status == 200:
                    # log.debug('Project_data {0} -- {1}'.format(project_id, content))
                    data = json.loads(content)
                    project_list[project] = data['name']
                else:
                    log.error('Project_data  Error {0} -- {1}'.format(project_id, resp.status))


            else:
                log.error('Access Token Error {0}'.format(resp_access.status))

    except Exception as e:
        log_error(e)

    return project_list
def get_center_list(unique):
    log_output('in get center list ------')
    log_output(unique)
    cost_center_list = []

    project_unique_ids = []

    if unique:
        center_list = get_cost_centers(unique)
        log_output(center_list)

        for (cost_center) in center_list:
            cost_center_list.append(cost_center[0])

        cost_center_list.append('other')
    else:
        center_list = get_cost_centers(unique)
        log_output(center_list)

        for center in center_list:
            project = dict()
            center_data = json.loads(json.dumps(center, cls=AlchemyEncoder))
            project['cost_center'] = center_data['cost_center']
            project['project_id'] = center_data['project_id']
            project['project_name'] = center_data['project_name']
            project['director'] = center_data['director']

            project_unique_ids.append(center_data['project_id'])

            cost_center_list.append(project)

        project_list = get_distinct_projects()

        log_output('In Project List')
        log_output(project_list)

        for project in project_list:
            if project[0] not in project_unique_ids:
                cost_center_list.append(
                    dict(cost_center='other', project_id=project[0], project_name=project[0], director='None'))

    return cost_center_list