Skip to content

Commit

Permalink
common: updates pycountry to country_converter package
Browse files Browse the repository at this point in the history
Signed-off-by: pamfilos <[email protected]>
  • Loading branch information
pamfilos committed Aug 23, 2024
1 parent 80156a3 commit 916b628
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions dags/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +33,7 @@
from structlog import get_logger

logger = get_logger()

cc = coco.CountryConverter()

def set_harvesting_interval(repo, **kwargs):
if (
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ busypie==0.4.5
pydantic
jsonschema
plyvel
pycountry
country_converter
inspire-utils

0 comments on commit 916b628

Please sign in to comment.