Skip to content

Commit

Permalink
Fixed country.py to be able to run multiple translate().
Browse files Browse the repository at this point in the history
  • Loading branch information
sahawut committed Apr 18, 2017
1 parent d123ff7 commit a3ed87a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 12 additions & 2 deletions country.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


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:
Expand Down Expand Up @@ -37,12 +39,20 @@ def translate(ids):
aid.log_time()
sys.stdout = common
sys.stderr = common
sys.stderr = sys_stderr
sys.stdout = sys_stdout


def test():
translate(['fji'])


def _create(ids):
log_path = aid.make_path('logs/')
for iso3 in ids:
stdout = log_path + iso3 + '.out'
aid.touch_file(stdout)


if __name__ == "__main__":
translate(spew.find_ipums_countries_ids())
translate([spew.ISO3_CANADA])
translate(spew.find_all_country_ids_except_usa())
8 changes: 3 additions & 5 deletions spew.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ def find_country_by_iso3(iso3):
return files[0]


def find_all_countries():
def find_all_countries_except_usa():
country_outputs = find_countries('*/output')
return [o.replace('/output', '') for o in country_outputs]


def find_ipums_countries_ids():
ids = [o.split('/')[-1] for o in find_all_countries()]
ids.remove(ISO3_CANADA)
return ids
def find_all_country_ids_except_usa():
return [o.split('/')[-1] for o in find_all_countries_except_usa()]


def find_countries(iso3):
Expand Down

0 comments on commit a3ed87a

Please sign in to comment.