import sys
import xml.etree.ElementTree as ET


def main():
    corpusRoot = ET.Element("teiCorpus")

    for j in range(1, len(sys.argv)):
        try:
            doc_data = extract_data(sys.argv[j])
            doc_tree = create_tree(doc_data, j-1)
            currentRoot = doc_tree.getroot()
            corpusRoot.append(currentRoot)
        except:
            print("Warning: could not parse file: " + sys.argv[j], file=sys.stderr) 
            continue

    corpusTree = ET.ElementTree(corpusRoot)
    ET.indent(corpusTree, "  ")
    corpusTree.write(sys.stdout, encoding='unicode')


def extract_data(file):
    ''' Parses an xml file and saves the metadata and texts into a dictionary that is returned.
    The dictionary is of the following form:
    data = {filenumber: {title}, {url}, {author}, {date}, {time}, {text}}
    '''

    tree = ET.parse(file)
    root = tree.getroot()
    ET.register_namespace("", "http://www.tei-c.org/ns/1.0")

    data = {}

    for i, text in enumerate(root.iter("{http://www.tei-c.org/ns/1.0}text")):
        data[i] = {}
        data[i]['title'] = text.get('title')
        data[i]['url'] = text.get('url')
        data[i]['author'] = text.get('author')
        data[i]['date'] = text.get('date').split(' ')[0]
        data[i]['time'] = text.get('date').split(' ')[1]

        textelem = text.find(".{http://www.tei-c.org/ns/1.0}body/{http://www.tei-c.org/ns/1.0}div/"\
                             "{http://www.tei-c.org/ns/1.0}div")
    
        data[i]['text'] = []
        for p in textelem.findall(".{http://www.tei-c.org/ns/1.0}p"):
            data[i]['text'].append(p)
    
    return data


def create_tree(data, filenumber):
    ''' Receives a dictionary containing the data and returns an xml tree in the 
    desired format. Generates text sigles of the following format: BNC/filenumber.textnumber,
    e.g. BNC/000.00000
    '''
    docRoot = ET.Element("teiDoc")

    for i in range(len(data)):
        tei = ET.SubElement(docRoot, "TEI")
        teiHeader = ET.SubElement(tei, "teiHeader")
        fileDesc = ET.SubElement(teiHeader, "fileDesc")
        titleStmt = ET.SubElement(fileDesc, "titleStmt")
        textSigle = ET.SubElement(titleStmt, "textSigle")
        textSigle.text = "BNC/" + f"{filenumber:03}" + "." + f"{i:05}"
        sourceDesc = ET.SubElement(fileDesc, "sourceDesc")
        analytic = ET.SubElement(sourceDesc, "analytic")
        htitle = ET.SubElement(analytic, "h.title")
        htitle.text = data[i]['title']
        hauthor = ET.SubElement(analytic, "h.author")
        hauthor.text = data[i]['author']
        imprint = ET.SubElement(sourceDesc, "imprint")
        pubDateYear = ET.SubElement(imprint, "pubDate")
        pubDateYear.set("type", "year")
        pubDateYear.text = data[i]['date'][0:4]
        pubDateMonth = ET.SubElement(imprint, "pubDate")
        pubDateMonth.set("type", "month")
        pubDateMonth.text = data[i]['date'][5:7]
        pubDateDay = ET.SubElement(imprint, "pubDate")
        pubDateDay.set("type", "day")
        pubDateDay.text = data[i]['date'][8:10]
        pubDateTime = ET.SubElement(imprint, "pubDate")
        pubDateTime.set("type", "time")
        pubDateTime.text = data[i]['time']
        pubPlace = ET.SubElement(imprint, "pubPlace")
        ref = ET.SubElement(pubPlace, "ref")
        ref.set("type", "page_url")
        ref.set("target", data[i]['url'])
        text = ET.SubElement(tei, "text")
        body = ET.SubElement(text, "body")
        for p in data[i]['text']:
            body.append(p)

    docTree = ET.ElementTree(docRoot)
    ET.indent(docTree, "  ")

    return docTree


main()