diff --git a/dags/common/utils.py b/dags/common/utils.py index 2399165c..76f36c2c 100644 --- a/dags/common/utils.py +++ b/dags/common/utils.py @@ -12,7 +12,7 @@ from inspire_utils.record import get_value import backoff -import pycountry +import country_converter as coco import requests from airflow.models.dagrun import DagRun from airflow.utils.state import DagRunState @@ -33,7 +33,7 @@ from structlog import get_logger logger = get_logger() - +cc = coco.CountryConverter() def set_harvesting_interval(repo, **kwargs): if ( @@ -308,7 +308,14 @@ def parse_country_from_value(affiliation_value): return val try: - mapped_countries = pycountry.countries.search_fuzzy(country) + country_code = cc.convert(country, to="iso2") + mapped_countries = [] + if country_code != "not found": + mapped_countries = [{ + "code": country_code, + "name": cc.convert(country, to="name_short"), + }] + if len(mapped_countries) > 1 or len(mapped_countries) == 0: raise FoundMoreThanOneMatchOrNone(affiliation_value) return mapped_countries[0].name diff --git a/requirements.txt b/requirements.txt index 3ee8faa6..82aaf8da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,5 +9,5 @@ busypie==0.4.5 pydantic jsonschema plyvel -pycountry +country_converter inspire-utils