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
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
def translate(states): print('Started translating counties in', states) path = 'logs/' aid.mkdir(path) with open(path + 'counties.' + str(datetime.now()), 'w') as common: sys.stdout = common sys.stderr = common print('Translating', states) for state in states: if state == 'input': continue aid.log_time('Translating state ID = ' + state) try: pp_csvs = spew.find_csvs(conf.pp_prefix, state) counties = set([to_county_id(csv) for csv in pp_csvs]) print(counties, flush=True) for county in counties: try: prefix = path + state + '/' + county stdout = prefix + '.out' aid.mkdir(stdout) if os.path.exists(stdout): print( stdout, 'already exists. Delete it if you want to rerun.' ) continue aid.log_time('Translating county ID = ' + county) sys.stdout = open(stdout, 'w') sys.stderr = open(prefix + '.err', 'w') us.translate(county) except Exception as e: aid.log_error(e) finally: aid.log_time() sys.stdout = common sys.stderr = common except Exception as e: aid.log_error(e) finally: aid.log_time() sys.stdout = common sys.stderr = common aid.log_time('Done')