Fix formatting

This commit is contained in:
2021-09-08 20:39:46 +02:00
parent fb6ca1da51
commit 512cb17264
3 changed files with 29 additions and 10 deletions

View File

@@ -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

View File

@@ -27,3 +27,8 @@ A file nevében ne legyen ékezetes karakter.
Egy sor sem lehet 50 karakternél hosszabb!
## Telepítés
```shell
pip install -r requirements.txt
```

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
xmlformatter