diff --git a/tei2imxml.py b/tei2imxml.py index 400714b..6edee7f 100644 --- a/tei2imxml.py +++ b/tei2imxml.py @@ -13,6 +13,7 @@ import pickle import shlex import configparser +import libeoaconvert from datetime import datetime from bs4 import BeautifulSoup from lxml import etree, objectify @@ -103,7 +104,7 @@ def get_field(xml_tree, query_path, mandatory=False, findall=False): info_dict['eoa_translators'] = get_field(xml_tree, "//t:teiHeader/t:fileDesc/t:titleStmt/t:editor[@role='translator']", findall=True) info_dict['eoa_keywords'] = get_field(xml_tree, "//t:teiHeader/t:profileDesc/t:textClass/t:keywords/t:list/t:item", findall=True) info_dict['eoa_authors'] = get_field(xml_tree, "//t:teiHeader/t:fileDesc/t:titleStmt/t:author", findall=True) - + info_dict['eoa_editors'] = get_field(xml_tree, "//t:teiHeader/t:fileDesc/t:titleStmt/t:editor", findall=True) return info_dict # def get_publication_info ends here @@ -156,17 +157,42 @@ def make_publication_cfg(info_dict): general_config['Dedication'] = info_dict['eoa_dedication'] #ok general_config['Translator'] = ", ".join(info_dict['eoa_translators']) - if len(info_dict['eoa_authors']) > 5: - sys.exit("Too many authors. Up to 5 are allowed. Exiting.") + number_of_authors = len(info_dict['eoa_authors']) + number_of_editors = len(info_dict['eoa_editors']) + + if number_of_authors > 0 and number_of_editors > 0: + print("Found both editor and authors. This is not permitted. Exiting") + sys.exit() + elif number_of_authors == 0 and number_of_editors == 0: + print("Found neither editor nor authors. Please fill in. Exiting") + sys.exit() + elif number_of_authors > 5 or number_of_editors > 5: + print("Only a maximum of 5 authors or editors allowed. Exiting") + sys.exit() + elif number_of_authors == 0 and number_of_editors in range(1,6): + EDITED_VOLUME = True + elif number_of_authors in range(1,6) and number_of_editors == 0: + EDITED_VOLUME = False else: - for entry in range(0, 5): - author_label = "Author" + str(entry + 1) - try: - authors_config[author_label] = info_dict['eoa_authors'][entry] - except IndexError: - authors_config[author_label] = "" + print("num authors: ", number_of_authors) + print("num editors: ", number_of_editors) + print("Something went wrong with the number of authors end editors. Please check. Exiting") + sys.exit() - authors_config['Zusatz'] = "" + for entry in range(0, 5): + author_label = "Author" + str(entry + 1) + try: + if EDITED_VOLUME == True: + authors_config[author_label] = info_dict['eoa_editors'][entry] + if number_of_editors == 1: + authors_config['Zusatz'] = "({})".format(libeoaconvert.dict_ed[info_dict['eoa_language']].capitalize()) + else: + authors_config['Zusatz'] = "({})".format(libeoaconvert.dict_eds[info_dict['eoa_language']].capitalize()) + else: + authors_config[author_label] = info_dict['eoa_authors'][entry] + authors_config['Zusatz'] = "" + except IndexError: + authors_config[author_label] = "" output_filename = OUTPUT_DIR + os.path.sep + "publication.cfg" with open(output_filename, 'w') as configfile: @@ -283,13 +309,15 @@ def transform_body(xml_tree, cited_data, authors, publang): chapter_title = chapter.find("t:head", namespaces=NS_MAP) - if authors is not None: - if len(authors) == 1: - eoa_author = authors[0] - eoa_author.tag = "EOAauthor" - chapter_title.insert(0, eoa_author) - else: - print("Found more than one author. Please advise") + author_ids = chapter.get("resp") + list_author_id = author_ids.split(" ") + + if len(list_author_id) > 0: + author_string = format_authors(list_author_id, publang) + # print(author_string) + eoa_author = etree.Element("EOAauthor") + eoa_author.text = author_string + chapter_title.insert(0, eoa_author) chapter.insert(0, chapter_title)