diff --git a/requirements.txt b/requirements.txt index a44eb5c..7aea70f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,7 @@ charset-normalizer==3.4.0 # via requests click==8.1.7 # via typer -coverage==7.6.5 +coverage==7.6.7 # via pytest-cov distlib==0.3.9 # via virtualenv diff --git a/src/hdx/location/country.py b/src/hdx/location/country.py index ed1ec26..dbdb239 100755 --- a/src/hdx/location/country.py +++ b/src/hdx/location/country.py @@ -74,7 +74,11 @@ class Country: _countriesdata = None _ochaurl_default = "https://docs.google.com/spreadsheets/d/1NjSI2LaS3SqbgYc0HdD8oIb7lofGtiHgoKKATCpwVdY/export?format=csv&gid=1088874596" _ochaurl = _ochaurl_default - _ochapath = None + _ochapath_default = script_dir_plus_file( + "Countries & Territories Taxonomy MVP - C&T Taxonomy with HXL Tags.csv", + CountryError, + ) + _ochapath = _ochapath_default _country_name_overrides = {} _country_name_mappings = {} @@ -239,14 +243,8 @@ def countriesdata( "Download from OCHA feed failed! Falling back to stored file." ) if countries is None: - file_path = script_dir_plus_file( - "Countries & Territories Taxonomy MVP - C&T Taxonomy with HXL Tags.csv", - CountryError, - ) - if cls._ochapath: - file_path = cls._ochapath countries = hxl.data( - file_path, + cls._ochapath, InputOptions(allow_local=True, encoding="utf-8"), ) cls.set_countriesdata(countries) @@ -269,7 +267,7 @@ def set_use_live_default(cls, use_live: Optional[bool] = None) -> None: cls._use_live = use_live @classmethod - def set_ocha_url(cls, url: Optional[str] = None) -> None: + def set_ocha_url(cls, url: str = None) -> None: """ Set OCHA url from which to retrieve countries data @@ -294,8 +292,8 @@ def set_ocha_path(cls, path: Optional[str] = None) -> None: Returns: None """ - if path and not os.path.exists(path): - path = None + if not path or (path and not os.path.exists(path)): + path = cls._ochapath_default cls._ochapath = path @classmethod