def main(): cn_name_format = COUNTRY_NAME_FORMAT_UPPER for key, value in sorted(map_countries(cn_name_format).items()): pprint({key: value}) try: cn_continent = country_alpha2_to_continent_code('AA') pprint(cn_continent) except KeyError as kerr: print("Key error: {0}".format(kerr)) except: print("Unexpected error:", sys.exc_info()[0]) try: cn_continent = country_alpha2_to_continent_code(None) pprint(cn_continent) except KeyError as kerr: print("Key error: {0}".format(kerr)) except: print("Unexpected error:", sys.exc_info()[0]) cn_continent = country_alpha2_to_continent_code('US') pprint(cn_continent) cn_continent = country_alpha2_to_continent_code('AU') pprint(cn_continent) cn_continent = country_alpha2_to_continent_code('NZ') pprint(cn_continent) cn_continent = country_alpha2_to_continent_code('JP') pprint(cn_continent) cn_name = country_alpha2_to_country_name('JP', cn_name_format) pprint(cn_name) cn_a2_code = country_name_to_country_alpha2('USA', cn_name_format) pprint(cn_a2_code) cn_a2_code = country_name_to_country_alpha2('United States', cn_name_format) pprint(cn_a2_code) cn_a2_code = country_name_to_country_alpha2('South Korea', cn_name_format) pprint(cn_a2_code) cn_name = country_alpha2_to_country_name(cn_a2_code, cn_name_format) pprint(cn_name) cn_name = country_alpha2_to_country_name('RU', cn_name_format) pprint(cn_name) cn_a2_code = country_name_to_country_alpha2(cn_name, cn_name_format) pprint(cn_a2_code) cn_a2_code = country_alpha3_to_country_alpha2('RUS') pprint(cn_a2_code) cn_name = country_alpha2_to_country_name('GB', cn_name_format) pprint(cn_name) cn_name = country_alpha2_to_country_name('US', cn_name_format) pprint(cn_name)
def get_continent(country): ex = {'England': 'Europe'} cn_codes = { 'AF': 'Africa', 'AS': 'Asia', 'EU': 'Europe', 'NA': 'North America', 'OC': 'Oceania', 'SA': 'South America' } pc_dict = pc.map_countries() try: a3 = pc_dict[country]['alpha_2'] cn = pc.country_alpha2_to_continent_code(a3) return (cn_codes[cn]) except: return (ex[country])
def test_get_countries(self): cn_dict = map_countries() assert (cn_dict) assert (len(cn_dict) > 0)
INPUT_CSV = [ "..\\data\\income_pre_tax.csv", "..\\data\\income_pre_p99p100.csv", "..\\data\\average_income.csv" ] LABELS = ["income share", "income share", "average income"] OUTPUT_JSON = [ "..\\data\\income_pre_tax.json", "..\\data\\income_pre_p99p100.json", "..\\data\\average_income.json" ] CURRENCIES_IN = "..\\data\\currencies.csv" CURRENCIES_OUT = "..\\data\\currencies.json" dataframes = [] if __name__ == '__main__': country_map = convert.map_countries() def transform(country_name): """ Input is a country name, returns an ISO 3 country code. """ if country_name in country_map: return country_map[country_name]["alpha_3"] elif country_name == "USA": return country_name else: return None # Make a json with the currency information. currency_df = pd.read_csv(CURRENCIES_IN,