def test_get_iso3_from_m49(self): assert Country.get_iso3_from_m49(4, use_live=False) == 'AFG' assert Country.get_iso3_from_m49(882, use_live=False) == 'WSM' assert Country.get_iso3_from_m49(9999, use_live=False) is None with pytest.raises(LocationError): Country.get_iso3_from_m49(9999, use_live=False, exception=LocationError)
def get_slumratios(url, downloader): stream = downloader.get_tabular_stream(url, headers=1, format='csv', compression='zip') years = set() for header in stream.headers: try: int(header) years.add(header) except ValueError: pass years = sorted(years, reverse=True) slumratios = dict() for row in stream.iter(keyed=True): if not row: break iso3 = Country.get_iso3_from_m49(int(row['CountryCode'])) if iso3 is None: continue for year in years: value = row.get(year) if value and value != ' ': slumratios[iso3] = float(value) / 100.0 return slumratios
def get_countries(countries_url, downloader): countries = list() headers, iterator = downloader.get_tabular_rows(countries_url, headers=1, dict_form=True, format='xlsx') for row in iterator: m49 = row['ISO Code'] if not m49: continue iso3 = Country.get_iso3_from_m49(m49) countryname = Country.get_country_name_from_iso3(iso3) countries.append({'m49': m49, 'iso3': iso3, 'countryname': countryname}) return countries
def get_countriesdata(countries_url, downloader): countries = list() for row in downloader.get_tabular_rows(countries_url, dict_rows=True, headers=1, format='xlsx'): # country = row['Name'] # iso3, _ = Country.get_iso3_country_code_fuzzy(country, exception=ValueError) # m49 = Country.get_m49_from_iso3(iso3) m49 = row['ISO Country Number'] if not m49: continue iso3 = Country.get_iso3_from_m49(m49) countryname = Country.get_country_name_from_iso3(iso3) countries.append({'m49': m49, 'iso3': iso3, 'countryname': countryname}) return countries
def test_get_iso3_from_m49(self): assert Country.get_iso3_from_m49(4) == 'AFG' assert Country.get_iso3_from_m49(882) == 'WSM' assert Country.get_iso3_from_m49(9999) is None with pytest.raises(LocationError): Country.get_iso3_from_m49(9999, exception=LocationError)