From a57919b05d8b1f24041713e85b7fa4322c0591c6 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Thu, 26 Dec 2019 17:24:50 +0100 Subject: datacite: use iso 639-1 codes --- python/fatcat_tools/importers/datacite.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'python/fatcat_tools/importers') diff --git a/python/fatcat_tools/importers/datacite.py b/python/fatcat_tools/importers/datacite.py index 19b89edf..26520164 100644 --- a/python/fatcat_tools/importers/datacite.py +++ b/python/fatcat_tools/importers/datacite.py @@ -10,7 +10,7 @@ import datetime import fatcat_openapi_client import hashlib import json -import langcodes +import pycountry import langdetect import sqlite3 import sys @@ -433,12 +433,9 @@ class DataciteImporter(EntityImporter): value = attributes.get('language', '') or '' try: - language = langcodes.find(value).language - except LookupError: - try: - language = langcodes.get(value).language - except langcodes.tag_parser.LanguageTagError: - pass + language = pycountry.languages.lookup(value).alpha_2 + except (LookupError, AttributeError) as err: + print('language lookup miss for {}: {}'.format(value, err), file=sys.stderr) # Abstracts appear in "attributes.descriptions[].descriptionType", some # of the observed values: "Methods", "TechnicalInfo", -- cgit v1.2.3