예제 #1
0
def translate(ids):
    sys_stderr = sys.stderr
    sys_stdout = sys.stdout
    print('Started translating countries in', ids)
    log_path = aid.make_path('logs/')
    with open(log_path + 'countries.' + str(datetime.now()), 'w') as common:
        sys.stdout = common
        sys.stderr = common
        print('Translating countries with ISO 3166-1 alpha-3 in ', ids)
        for iso3 in ids:
            if iso3 == 'input':
                continue
            stdout = log_path + iso3 + '.out'
            if os.path.exists(stdout):
                print(stdout, 'already exists. Delete it if you want to rerun.')
                continue
            aid.log_time('Translating ' + iso3)
            with open(stdout, 'w') as sys.stdout:
                with open(log_path + iso3 + '.err', 'w') as sys.stderr:
                    aid.log_time()
                    try:
                        if iso3 == spew.ISO3_CANADA:
                            canada.translate(iso3)
                        else:
                            ipums.translate(iso3)
                    except Exception as e:
                        aid.log_error(e)
                    finally:
                        aid.log_time()
                        sys.stdout = common
                        sys.stderr = common
    sys.stderr = sys_stderr
    sys.stdout = sys_stdout
예제 #2
0
def translate(states):
    print('Started translating states in', states)
    log_path = aid.make_path('logs/')
    with open(log_path + 'states.' + str(datetime.now()), 'w') as common:
        sys.stdout = common
        sys.stderr = common
        print('Translating', states)
        for state in states:
            if state == 'input':
                continue
            stdout = log_path + state + '.out'
            if os.path.exists(stdout):
                print(stdout,
                      'already exists. Delete it if you want to rerun.')
                continue
            aid.log_time('Translating ' + state)
            with open(stdout, 'w') as sys.stdout:
                with open(log_path + state + '.err', 'w') as sys.stderr:
                    aid.log_time()
                    try:
                        us.translate(state)
                    except Exception as e:
                        aid.log_error(e)
                    finally:
                        aid.log_time()
                        sys.stdout = common
                        sys.stderr = common
예제 #3
0
def _create(ids):
    log_path = aid.make_path('logs/')
    for iso3 in ids:
        stdout = log_path + iso3 + '.out'
        aid.touch_file(stdout)