import os, sys
import xml.etree.ElementTree as ET
from xml.dom import minidom
import traceback
import sys

def main():
    # Create corpus structure from string and save into file 
    corpus = "<teiCorpus>\n</teiCorpus>"
    origRoot = ET.fromstring(corpus)
    corpusStr = minidom.parseString(ET.tostring(origRoot)).toprettyxml(indent="  ")
    if not os.path.exists('input'):
        os.makedirs("input")
    if not os.path.exists('output'):
        os.makedirs("output")
    with open("input/tree_structure.xml", "w") as f:
        f.write(corpusStr)

    # Parse corpus tree
    corpusTree = ET.parse("input/tree_structure.xml")
    corpusRoot = corpusTree.getroot()

    # Process documents and append to corpus tree
    for j in range(1, len(sys.argv)):
      try:
         currentTree = convert(j-1, sys.argv[j])
         currentRoot = currentTree.getroot()
         corpusRoot.append(currentRoot)
      except:
         print("ERROR:"+sys.argv[j])
         print(traceback.format_exc())
         print(sys.exc_info()[2])
         continue

    # Indent and save tree
    ET.indent(corpusTree, "  ")
    corpusTree.write("output/GA_corpus.p5.xml", encoding='utf-8', xml_declaration=True, method='xml', short_empty_elements=True)


def convert(j, file):
    # Parse document tree and get root
    tree = ET.parse(file)
    root = tree.getroot()
    ET.register_namespace("", "http://www.tei-c.org/ns/1.0")
 
    # Store metadata and texts in lists
    titles = root.find(".//*{http://www.tei-c.org/ns/1.0}bibl/{http://www.tei-c.org/ns/1.0}title")
    uris = root.find(".//*{http://www.tei-c.org/ns/1.0}bibl/{http://www.tei-c.org/ns/1.0}pubPlace")
    authors = root.findall(".//*{http://www.tei-c.org/ns/1.0}bibl/{http://www.tei-c.org/ns/1.0}author")
    
    dates = root.find(".//*{http://www.tei-c.org/ns/1.0}bibl/{http://www.tei-c.org/ns/1.0}date")
    texts = root.findall(".//*{http://www.tei-c.org/ns/1.0}body/{http://www.tei-c.org/ns/1.0}div")
    domains = root.find(".//*[@type]")

    # Count text elements 
    number_of_texts = 0
    for text in root.iter("{http://www.tei-c.org/ns/1.0}text"):
        for body in text:
            for div in body:
                number_of_texts+=1

    number_of_texts = len(texts)
    # Remove all elements from root
    for elem in root.findall("*"):
        root.remove(elem)

    # Rename root
    root.tag = "teiDoc"
    
    # Create target structure
    for i in range(number_of_texts):
        tei = ET.SubElement(root, "TEI")
        teiHeader = ET.SubElement(tei, "teiHeader")
        fileDesc = ET.SubElement(teiHeader, "fileDesc")
        titleStmt = ET.SubElement(fileDesc, "titleStmt")
        textSigle = ET.SubElement(titleStmt, "textSigle")
        textSigle.text = "GA/" + f"{j:03}" + "." + f"{i:05}"
        sourceDesc = ET.SubElement(fileDesc, "sourceDesc")
        analytic = ET.SubElement(sourceDesc, "analytic")
        title = ET.SubElement(titleStmt, "title")
        title.text = titles.text
        
        print(textSigle.text, end='\n')
        

        for author in authors :
            hauthor = ET.SubElement(analytic, "h.author")
            hauthor.text = author.text
            print(hauthor.text, end='\n')
        imprint = ET.SubElement(sourceDesc, "imprint")
        pubDateYear = ET.SubElement(imprint, "pubDate")
        pubDateYear.set("type", "year")
        pubDateYear.text = dates.text
        pubDateMonth = ET.SubElement(imprint, "pubDate")
        pubDateMonth.set("type", "month")
        #pubDateMonth.text = datesPublished[i].text
        pubDateDay = ET.SubElement(imprint, "pubDate")
        pubDateDay.set("type", "day")
        #pubDateDay.text = datesPublished[i].text
        pubPlace = ET.SubElement(imprint, "pubPlace")
        idno = ET.SubElement(pubPlace, "idno")
        idno.set("type", "URI")
        idno.text = uris.text
        domain = ET.SubElement(titleStmt, "domain")
        domain.text = domains.get("type")
        '''
        splitFName = file.split("/")
        if (splitFName[-2] in ['Persuasive', 'Blog']):
            domain.text = splitFName[-2]
        elif(splitFName[-4] != "Originaldaten"):
            domain.text = splitFName[-4] + ':' + splitFName[-3] + ':' + splitFName[-2]
        else:
            domain.text = splitFName[-3] + ':' + splitFName[-2]
        '''
        domain.text = domain.text.replace("_hobbies", "_Hobbies")
        text = ET.SubElement(tei, "text")
        text.append(texts[i])  
        

    return tree


main()