human
Complete this python program:
def get_canonical_ids(accounts, override=False):
assistant
#Here is the Python program you requested.

    """Given a list of AWS Account IDs, reach out to AWS to fetch the Canonical IDs
    :param override:
    :param accounts:
    :return:
    """
    if (not override):
        app.logger.info('[@]    Override    flag    was    not    passed    in    --    will    skip    over    accounts    with    a    canonical    ID    associated.')
    for account in accounts:
        current_canonical = AccountTypeCustomValues.query.filter((AccountTypeCustomValues.name == 'canonical_id'), (AccountTypeCustomValues.account_id == account.id)).first()
        if ((not override) and current_canonical):
            app.logger.info('[/]    Account    {}    already    has    a    canonical    ID    associated...    Skipping...'.format(account.name))
            continue
        @iter_account_region('s3', accounts=[account.identifier], regions=['us-east-1'], assume_role=(account.getCustom('role_name') or 'SecurityMonkey'), session_name='SecurityMonkey', conn_type='dict')
        def loop_over_accounts(**kwargs):
            app.logger.info('[-->]    Fetching    canonical    ID    for    account:    {}'.format(account.name))
            return fetch_id(index='s3', exception_record_region='us-east-1', account_name=account.name, exception_map={}, **kwargs)
        result = loop_over_accounts()
        if (not result):
            app.logger.error('[x]    Did    not    receive    a    proper    response    back.    Check    the    exception    log    for    details.')
            continue
        app.logger.info('[+]    Associating    Canonical    ID:    {}    with    account:    {}'.format(result[0]['Owner']['ID'], account.name))
        if (not current_canonical):
            current_canonical = AccountTypeCustomValues(account_id=account.id, name='canonical_id')
        current_canonical.value = result[0]['Owner']['ID']
        db.session.add(current_canonical)
        db.session.commit()