From 6c738b8358ecccf0a1567c4355981e0a21821d28 Mon Sep 17 00:00:00 2001 From: kthoden Date: Wed, 15 May 2019 16:58:27 +0200 Subject: [PATCH] Handle bibliography entries without keywords --- eoatex2imxml.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/eoatex2imxml.py b/eoatex2imxml.py index 19ae5ee..8767b0e 100755 --- a/eoatex2imxml.py +++ b/eoatex2imxml.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8; mode: python -*- -# Time-stamp: <2019-05-14 17:09:18 (kthoden)> +# Time-stamp: <2019-05-15 16:51:31 (kthoden)> """ Converts Latex files into a customized DocBook XML file. @@ -1185,9 +1185,23 @@ def bib_keywords_sanity_check( # just for debugging (?): logging.info("We want to collect the entries matching the keywords from the database.") - citations_with_keyword = [x["id"] for x in citations_json if keyword in x["keyword"]] - logging.debug(f"Found {libeoaconvert.plural(len(citations_with_keyword), 'citation')} with keyword {keyword} in database.") + citations_with_keyword = [] + citations_without_keyword = [] + # citations_with_keyword = [x["id"] for x in citations_json if keyword in x["keyword"]] + for cj in citations_json: + try: + if keyword in cj["keyword"]: + citations_with_keyword.append(cj["id"]) + except KeyError: + logging.warning(f"Index entry {cj['id']} has no keyword. As long as it is not cited, this is no problem.") + citations_without_keyword.append(cj["id"]) + pass + logging.debug(f"Found {libeoaconvert.plural(len(citations_with_keyword), 'citation')} with keyword {keyword} in database.") + cited_works_without_keyword = [x for x in citations_without_keyword if x in citekeys] + if cited_works_without_keyword: + logging.error(f"Found {libeoaconvert.plural(len(cited_works_without_keyword), 'work')} that are cited but have no keyword. Please assign one.") + sys.exit(1) citations_to_format = [x for x in citations_with_keyword if x in citekeys] logging.debug(f"Found {libeoaconvert.plural(len(citations_to_format), 'citation')} with keyword {keyword} that are actually cited.")