Compare commits

...

1 Commits

Author SHA1 Message Date
4405a19633 Prettify xml output 2021-08-31 00:00:12 +02:00
2 changed files with 18 additions and 8 deletions

View File

@@ -11,6 +11,7 @@ import xml.etree.ElementTree as ET
import csv
import datetime
import os
from bs4 import BeautifulSoup
# ---------------------------------------------------------------------------- #
@@ -182,24 +183,31 @@ while fileNameNotFound:
if not os.path.exists(fileName):
fileNameNotFound = False
print()
print(f'Fájl mentése ide: {fileName}')
print()
# --------------------------------- Write xml -------------------------------- #
# ------------------------------- Generate 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))
xmlString = ET.tostring(data)
# ------------------------------- Prettify xml ------------------------------- #
bs_data = BeautifulSoup(xmlString, 'xml')
prettyXml = bs_data.prettify()
print(prettyXml)
print()
tree = ET.ElementTree(data)
tree.write(fileName, encoding="utf-8", xml_declaration=True)
# --------------------------------- Save file -------------------------------- #
f = open(fileName, "x")
f.write(prettyXml)
f.close

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
beautifulsoup4
lxml