From b02aad21480b1edb458ff907090dad097b4e1846 Mon Sep 17 00:00:00 2001 From: lhess2021 Date: Fri, 20 May 2022 23:25:19 -0400 Subject: [PATCH] add xml header. add c_num, canticle attr to . start addTEIheader() for later --- scripts.d/py-scripts.d/parser-txt-to-xml.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts.d/py-scripts.d/parser-txt-to-xml.py b/scripts.d/py-scripts.d/parser-txt-to-xml.py index 63b561c..b5ee18e 100644 --- a/scripts.d/py-scripts.d/parser-txt-to-xml.py +++ b/scripts.d/py-scripts.d/parser-txt-to-xml.py @@ -138,8 +138,12 @@ def wrapTags(tag, xmlCantoFile): used to add , , and tags around body """ xmlCanto = getXMLFileName(xmlCantoFile) + cantoNum = str(int(xmlCanto.split('-')[0])) + canticle = xmlCanto.split('-')[1] if tag == 'TEI': openTag = '\n' + elif tag == 'canto': + openTag = '<' + tag + ' canticle="' + canticle + '"' + ' c_num="' + cantoNum + '">\n' else: openTag = '<' + tag + '>\n' closeTag = '\n' @@ -151,7 +155,7 @@ def wrapTags(tag, xmlCantoFile): xmlCantoContents.write(closeTag) xmlCantoContents.close() -def addTEIHeaderTags(xmlCantoFile): +def addTEIHeader(xmlCantoFile): """ The following is the minimum required TEI header @@ -177,6 +181,16 @@ def addTEIHeaderTags(xmlCantoFile): """ xmlCanto = getXMLFileName(xmlCantoFile) +def addXMLHeader(xmlCantoFile): + xmlCanto = getXMLFileName(xmlCantoFile) + xmlHeader = '\n\n' + with open(xmlCanto, 'r') as xmlCantoContents: + contents = xmlCantoContents.read() + with open(xmlCanto, 'w') as xmlCantoContents: + xmlCantoContents.write(xmlHeader) + xmlCantoContents.write(contents) + xmlCantoContents.close() + def addSpaces(xmlCantoFile): """ Add a given number of spaces before each opening and closing tag. @@ -238,9 +252,9 @@ def main(): wrapTags('tercets', xmlCantoName) wrapTags('canto', xmlCantoName) wrapTags('text', xmlCantoName) - #addTEIHeaderTags() wrapTags('TEI', xmlCantoName) addSpaces(xmlCantoName) + addXMLHeader(xmlCantoName) os.remove(cantoFile) # don't delete txt files while debugging so you don't have to keep copying them