Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Main method
  • Loading branch information
Klaus Thoden committed Aug 31, 2018
1 parent 91db5d1 commit 223e0c0
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions tei2imxml.py
Expand Up @@ -19,6 +19,7 @@
import subprocess
import pickle
import shlex
import argparse
import configparser
import libeoaconvert
from datetime import datetime
Expand Down Expand Up @@ -302,7 +303,7 @@ def format_pagerange(pagerange_start, pagerange_end):
return return_string
# def format_pagerange ends here

def format_authors(list_author_id, publang):
def format_authors(list_author_id, publang, xml_tree):
"""Retrieve author names from respStmt entries and format them."""

author_string = ""
Expand Down Expand Up @@ -354,7 +355,8 @@ def transform_body(xml_tree, cited_data, publang):
list_author_id = author_ids.split(" ")

if len(list_author_id) > 0:
author_string = format_authors(list_author_id, publang)
print("hier", list_author_id, publang)
author_string = format_authors(list_author_id, publang, xml_tree)
# print(author_string)
eoa_author = etree.Element("EOAauthor")
eoa_author.text = author_string
Expand Down Expand Up @@ -872,26 +874,27 @@ def fix_bib_entries(div_snippet):
return div_snippet
# def fix_bib_entries ends here

if __name__ == '__main__':
if len(sys.argv) == 1:
print("You must specify an input file!")
sys.exit()
elif len(sys.argv) > 2:
print("You can work with only one publication at a time!")
sys.exit()
def main():
"""Main function"""

data_pickle = TMP_DIR + os.path.sep + 'data.pickle'

parser = argparse.ArgumentParser()
parser.add_argument("-d", "--pickleddata", default=data_pickle, help="Pickled data file to be used.")
parser.add_argument("teifile", help="TEI XML file to convert into DocBook XML.")
args = parser.parse_args()

if not os.path.exists(TMP_DIR):
os.mkdir(os.path.expanduser(TMP_DIR))

try:
with open(TMP_DIR + os.path.sep + 'data.pickle', 'rb') as f:
with open(data_pickle, 'rb') as f:
data = pickle.load(f)
except FileNotFoundError:
print("File 'data.pickle' not found. You should run 'fix_tei.py' first. Exiting.")
sys.exit()

tei_document = sys.argv[-1]
xml_tree = etree.parse(tei_document)
xml_tree = etree.parse(args.teifile)

publication_language = xml_tree.xpath("//t:teiHeader/t:profileDesc/t:langUsage/t:language/@ident", namespaces=NS_MAP)[0]

Expand Down Expand Up @@ -1024,4 +1027,8 @@ def fix_bib_entries(div_snippet):

with open(output_filename, 'w') as amended_textfile:
amended_textfile.write(removed_namespace)
# def main ends here

if __name__ == '__main__':
main()
# finis

0 comments on commit 223e0c0

Please sign in to comment.