def add_country_location(self, country): # type: (str) -> None """Add a country. If an iso 3 code is not provided, value is parsed and if it is a valid country name, converted to an iso 3 code. If the country is already added, it is ignored. Args: country (str): Country to add Returns: None """ iso3, match = Location.get_iso3_country_code(country) if iso3 is None: raise HDXError('Country: %s - cannot find iso3 code!' % country) hdx_code, match = Location.get_HDX_code_from_location( iso3, self.configuration) if hdx_code is None: raise HDXError( 'Country: %s with iso3: %s could not be found in HDX list!' % (country, iso3)) groups = self.data.get('groups', None) if groups: if hdx_code in [x['name'] for x in groups]: return else: groups = list() groups.append({'name': hdx_code}) self.data['groups'] = groups
def add_other_location(self, location): # type: (str) -> None """Add a location which is not a country or continent. Value is parsed and compared to existing locations in HDX. If the location is already added, it is ignored. Args: location (str): Location to add Returns: None """ hdx_code, match = Location.get_HDX_code_from_location( location, self.configuration) if hdx_code is None: raise HDXError('Location: %s - cannot find in HDX!' % location) groups = self.data.get('groups', None) if groups: if hdx_code in [x['name'] for x in groups]: return else: groups = list() groups.append({'name': hdx_code}) self.data['groups'] = groups