Browse Source

add xml header. add c_num, canticle attr to <canto>. start addTEIheader() for later

main
lhess2021 4 years ago
parent
commit
b02aad2148
  1. 18
      scripts.d/py-scripts.d/parser-txt-to-xml.py

18
scripts.d/py-scripts.d/parser-txt-to-xml.py

@ -138,8 +138,12 @@ def wrapTags(tag, xmlCantoFile):
used to add <tercets>, <canto>, and <text> tags around <canto> body used to add <tercets>, <canto>, and <text> tags around <canto> body
""" """
xmlCanto = getXMLFileName(xmlCantoFile) xmlCanto = getXMLFileName(xmlCantoFile)
cantoNum = str(int(xmlCanto.split('-')[0]))
canticle = xmlCanto.split('-')[1]
if tag == 'TEI': if tag == 'TEI':
openTag = '<TEI xmlns="http://www.tei-c.org/ns/1.0">\n' openTag = '<TEI xmlns="http://www.tei-c.org/ns/1.0">\n'
elif tag == 'canto':
openTag = '<' + tag + ' canticle="' + canticle + '"' + ' c_num="' + cantoNum + '">\n'
else: else:
openTag = '<' + tag + '>\n' openTag = '<' + tag + '>\n'
closeTag = '\n</' + tag + '>' closeTag = '\n</' + tag + '>'
@ -151,7 +155,7 @@ def wrapTags(tag, xmlCantoFile):
xmlCantoContents.write(closeTag) xmlCantoContents.write(closeTag)
xmlCantoContents.close() xmlCantoContents.close()
def addTEIHeaderTags(xmlCantoFile): def addTEIHeader(xmlCantoFile):
""" """
The following is the minimum required TEI header The following is the minimum required TEI header
<TEI xmlns="http://www.tei-c.org/ns/1.0"> <TEI xmlns="http://www.tei-c.org/ns/1.0">
@ -177,6 +181,16 @@ def addTEIHeaderTags(xmlCantoFile):
""" """
xmlCanto = getXMLFileName(xmlCantoFile) xmlCanto = getXMLFileName(xmlCantoFile)
def addXMLHeader(xmlCantoFile):
xmlCanto = getXMLFileName(xmlCantoFile)
xmlHeader = '<?xml version="1.0" encoding="UTF-8"?>\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): def addSpaces(xmlCantoFile):
""" """
Add a given number of spaces before each opening and closing tag. Add a given number of spaces before each opening and closing tag.
@ -238,9 +252,9 @@ def main():
wrapTags('tercets', xmlCantoName) wrapTags('tercets', xmlCantoName)
wrapTags('canto', xmlCantoName) wrapTags('canto', xmlCantoName)
wrapTags('text', xmlCantoName) wrapTags('text', xmlCantoName)
#addTEIHeaderTags()
wrapTags('TEI', xmlCantoName) wrapTags('TEI', xmlCantoName)
addSpaces(xmlCantoName) addSpaces(xmlCantoName)
addXMLHeader(xmlCantoName)
os.remove(cantoFile) # don't delete txt files while debugging so you don't have to keep copying them os.remove(cantoFile) # don't delete txt files while debugging so you don't have to keep copying them

Loading…
Cancel
Save