Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Authors and editors
  • Loading branch information
Klaus Thoden committed May 29, 2018
1 parent 63c08a2 commit db5ddf5
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions tei2imxml.py
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit db5ddf5

Please sign in to comment.