Compare commits

..

3 Commits

Author SHA1 Message Date
4405a19633 Prettify xml output 2021-08-31 00:00:12 +02:00
141414e2b4 Check file extensions in folder 2021-06-23 17:32:14 +02:00
0209741dcf Fix single file input, newline and header in xml 2021-06-14 15:38:14 +02:00
2 changed files with 26 additions and 9 deletions

View File

@@ -11,6 +11,7 @@ import xml.etree.ElementTree as ET
import csv
import datetime
import os
from bs4 import BeautifulSoup
# ---------------------------------------------------------------------------- #
@@ -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)
@@ -178,11 +183,11 @@ 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')
for mérő in allXmlData:
@@ -191,8 +196,18 @@ for mérő in allXmlData:
a = ET.SubElement(currSub, adat)
a.text = mérő[adat]
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)
# --------------------------------- Save file -------------------------------- #
f = open(fileName, "x")
f.write(prettyXml)
f.close

2
requirements.txt Normal file
View File

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