Fix formatting
This commit is contained in:
@@ -11,6 +11,7 @@ import xml.etree.ElementTree as ET
|
||||
import csv
|
||||
import datetime
|
||||
import os
|
||||
import xmlformatter
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
@@ -147,7 +148,7 @@ for i, table in enumerate(csvArrs):
|
||||
xmlReqData = []
|
||||
for i, table in enumerate(reqData):
|
||||
print(f'Fájl ellenőrzése: {csvFileNames[i]}')
|
||||
|
||||
|
||||
# unwrap data
|
||||
currXmlData = getXmlData(table)
|
||||
|
||||
@@ -158,7 +159,7 @@ for i, table in enumerate(reqData):
|
||||
else:
|
||||
# remove bad lines
|
||||
print(wrongLines)
|
||||
for ele in sorted(wrongLines, reverse = True):
|
||||
for ele in sorted(wrongLines, reverse=True):
|
||||
del currXmlData[ele]
|
||||
print()
|
||||
xmlReqData.append(currXmlData)
|
||||
@@ -188,24 +189,36 @@ while fileNameNotFound:
|
||||
if not os.path.exists(fileName):
|
||||
fileNameNotFound = False
|
||||
|
||||
|
||||
print(f'Fájl mentése ide: {fileName}')
|
||||
print()
|
||||
|
||||
# --------------------------------- Write xml -------------------------------- #
|
||||
|
||||
data = ET.Element('Leolvasasok')
|
||||
data.tail = '\r\n'
|
||||
for mérő in allXmlData:
|
||||
currSub = ET.SubElement(data, 'Leolvasas')
|
||||
currSub.tail = '\r\n'
|
||||
for adat in mérő:
|
||||
a = ET.SubElement(currSub, adat)
|
||||
a.text = mérő[adat]
|
||||
a.tail = '\r\n'
|
||||
|
||||
print(ET.dump(data))
|
||||
print()
|
||||
xmlString = ET.tostring(data, encoding="utf-8", xml_declaration=True)
|
||||
|
||||
tree = ET.ElementTree(data)
|
||||
tree.write(fileName, encoding="utf-8", xml_declaration=True)
|
||||
# -------------------------------- Format xml -------------------------------- #
|
||||
|
||||
formatter = xmlformatter.Formatter(indent="2", indent_char=" ")
|
||||
formattedXml = formatter.format_string(xmlString)
|
||||
|
||||
# print(formattedXml)
|
||||
|
||||
# ----------------------------- Fix line endings ----------------------------- #
|
||||
|
||||
WINDOWS_LINE_ENDING = b'\r\n'
|
||||
UNIX_LINE_ENDING = b'\n'
|
||||
|
||||
formattedXml = formattedXml.replace(UNIX_LINE_ENDING, WINDOWS_LINE_ENDING)
|
||||
|
||||
# --------------------------------- Save file -------------------------------- #
|
||||
|
||||
f = open(fileName, "xb")
|
||||
f.write(formattedXml)
|
||||
f.close
|
||||
|
||||
Reference in New Issue
Block a user