Compare commits
3 Commits
4a6d34da4d
...
prettyfy1
| Author | SHA1 | Date | |
|---|---|---|---|
| 4405a19633 | |||
| 141414e2b4 | |||
| 0209741dcf |
@@ -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
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
beautifulsoup4
|
||||
lxml
|
||||
Reference in New Issue
Block a user