fix: Catch if country does not have alpha_2 attribute - fix #119

pull/121/head
mokaddem 2019-08-30 11:05:43 +02:00
parent 2f3fd08404
commit 19842f9445
1 changed files with 7 additions and 1 deletions

View File

@ -21,6 +21,7 @@ from phonenumbers import geocoder
class InvalidCoordinate(Exception):
pass
class Geo_helper:
def __init__(self, serv_redis_db, cfg):
self.serv_redis_db = serv_redis_db
@ -62,7 +63,12 @@ class Geo_helper:
print(error)
print("Please fix the above and try again.")
sys.exit(126)
self.country_to_iso = { country.name: country.alpha_2 for country in pycountry.countries}
self.country_to_iso = {}
for country in pycountry.countries:
try:
self.country_to_iso[country.name] = country.alpha_2
except AttributeError:
pass
with open(self.PATH_TO_JSON) as f:
self.country_code_to_coord = json.load(f)