|
|
|
|
@@ -11,6 +11,7 @@ import xml.etree.ElementTree as ET
|
|
|
|
|
import csv
|
|
|
|
|
import datetime
|
|
|
|
|
import os
|
|
|
|
|
import xmlformatter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- #
|
|
|
|
|
@@ -70,11 +71,11 @@ def getXmlData(data):
|
|
|
|
|
|
|
|
|
|
def checkData(xmlData):
|
|
|
|
|
print()
|
|
|
|
|
missingData = False
|
|
|
|
|
for mérő in xmlData:
|
|
|
|
|
missingData = []
|
|
|
|
|
for i, mérő in enumerate(xmlData):
|
|
|
|
|
for adat in mérő:
|
|
|
|
|
if len(mérő[adat]) == 0:
|
|
|
|
|
missingData = True
|
|
|
|
|
if len(mérő[adat]) == 0 or mérő[adat] == "diktalos":
|
|
|
|
|
missingData.append(i)
|
|
|
|
|
print(f'Adat hiányzik: "{adat}" a következő sorból:')
|
|
|
|
|
print(mérő)
|
|
|
|
|
return missingData
|
|
|
|
|
@@ -100,20 +101,24 @@ csvFileNames = []
|
|
|
|
|
if os.path.isdir(csvPath):
|
|
|
|
|
folder = csvPath
|
|
|
|
|
print(f'Fájlok a mappában: {os.listdir(csvPath)}')
|
|
|
|
|
for i, file in enumerate(os.listdir(csvPath)):
|
|
|
|
|
files = os.listdir(csvPath)
|
|
|
|
|
for file in os.listdir(csvPath):
|
|
|
|
|
if not os.path.splitext(file)[1] == '.csv':
|
|
|
|
|
files.remove(file)
|
|
|
|
|
print(f'Csv fájlok a mappában: {files}')
|
|
|
|
|
for i, file in enumerate(files):
|
|
|
|
|
csvFileNames.append(file)
|
|
|
|
|
with open(os.path.join(csvPath, file), newline='') as csvfile:
|
|
|
|
|
incsv = csv.reader(csvfile, delimiter=';')
|
|
|
|
|
csvArrs.append([])
|
|
|
|
|
|
|
|
|
|
for row in incsv:
|
|
|
|
|
csvArrs[i].append(row)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
csvFileNames[0] = csvPath
|
|
|
|
|
csvFileNames.append(csvPath)
|
|
|
|
|
with open(csvPath, newline='') as csvfile:
|
|
|
|
|
incsv = csv.reader(csvfile, delimiter=';')
|
|
|
|
|
csvArrs[0] = []
|
|
|
|
|
csvArrs.append([])
|
|
|
|
|
for row in incsv:
|
|
|
|
|
csvArrs[0].append(row)
|
|
|
|
|
|
|
|
|
|
@@ -143,16 +148,22 @@ 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)
|
|
|
|
|
if not checkData(currXmlData):
|
|
|
|
|
|
|
|
|
|
# check for missing data
|
|
|
|
|
wrongLines = checkData(currXmlData)
|
|
|
|
|
if len(wrongLines) == 0:
|
|
|
|
|
print('Fájl hibátlan')
|
|
|
|
|
else:
|
|
|
|
|
# remove bad lines
|
|
|
|
|
print(wrongLines)
|
|
|
|
|
for ele in sorted(wrongLines, reverse=True):
|
|
|
|
|
del currXmlData[ele]
|
|
|
|
|
print()
|
|
|
|
|
xmlReqData.append(currXmlData)
|
|
|
|
|
|
|
|
|
|
# print(xmlReqData)
|
|
|
|
|
# for i in xmlReqData:
|
|
|
|
|
# print(i)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------- Merge arrays ------------------------------- #
|
|
|
|
|
|
|
|
|
|
@@ -178,7 +189,6 @@ while fileNameNotFound:
|
|
|
|
|
if not os.path.exists(fileName):
|
|
|
|
|
fileNameNotFound = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(f'Fájl mentése ide: {fileName}')
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
@@ -191,8 +201,24 @@ for mérő in allXmlData:
|
|
|
|
|
a = ET.SubElement(currSub, adat)
|
|
|
|
|
a.text = mérő[adat]
|
|
|
|
|
|
|
|
|
|
print(ET.dump(data))
|
|
|
|
|
print()
|
|
|
|
|
xmlString = ET.tostring(data, encoding="utf-8", xml_declaration=True)
|
|
|
|
|
|
|
|
|
|
tree = ET.ElementTree(data)
|
|
|
|
|
tree.write(fileName)
|
|
|
|
|
# -------------------------------- 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
|
|
|
|
|
|