[countries] use ISO 3166 country name 5% of the time for general addresses, 10% of the time for OpenAddresses. Gives the parser examples of names like "Korea, Republic of" in #168

This commit is contained in:
Al
2017-03-25 19:41:59 -04:00
parent ecfa6855e7
commit 81c59e116a
5 changed files with 21 additions and 9 deletions

View File

@@ -52,6 +52,7 @@ class CountryNames(object):
self.base_dir = base_dir
self.country_alpha3_codes = {c.alpha2.lower(): c.alpha3.lower() for c in pycountry.countries}
self.iso_3166_names = {c.alpha2.lower(): c.name for c in pycountry.countries}
self.language_country_names = {}
self.country_language_names = defaultdict(dict)
@@ -177,7 +178,10 @@ class CountryNames(object):
return self.country_language_names.get(country_code, {}).get(language)
def alpha3_code(self, alpha2_code):
alpha3 = self.country_alpha3_codes.get(alpha2_code.lower())
alpha3 = self.country_alpha3_codes.get(alpha2_code.lower())
return alpha3.upper() if alpha3 else None
def iso_3166_name(self, alpha2_code):
return self.iso_3166_names.get(alpha2_code.lower())
country_names = CountryNames()