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 csv
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------- #
|
# ---------------------------------------------------------------------------- #
|
||||||
@@ -100,20 +101,24 @@ csvFileNames = []
|
|||||||
if os.path.isdir(csvPath):
|
if os.path.isdir(csvPath):
|
||||||
folder = csvPath
|
folder = csvPath
|
||||||
print(f'Fájlok a mappában: {os.listdir(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)
|
csvFileNames.append(file)
|
||||||
with open(os.path.join(csvPath, file), newline='') as csvfile:
|
with open(os.path.join(csvPath, file), newline='') as csvfile:
|
||||||
incsv = csv.reader(csvfile, delimiter=';')
|
incsv = csv.reader(csvfile, delimiter=';')
|
||||||
csvArrs.append([])
|
csvArrs.append([])
|
||||||
|
|
||||||
for row in incsv:
|
for row in incsv:
|
||||||
csvArrs[i].append(row)
|
csvArrs[i].append(row)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
csvFileNames[0] = csvPath
|
csvFileNames.append(csvPath)
|
||||||
with open(csvPath, newline='') as csvfile:
|
with open(csvPath, newline='') as csvfile:
|
||||||
incsv = csv.reader(csvfile, delimiter=';')
|
incsv = csv.reader(csvfile, delimiter=';')
|
||||||
csvArrs[0] = []
|
csvArrs.append([])
|
||||||
for row in incsv:
|
for row in incsv:
|
||||||
csvArrs[0].append(row)
|
csvArrs[0].append(row)
|
||||||
|
|
||||||
@@ -178,11 +183,11 @@ while fileNameNotFound:
|
|||||||
if not os.path.exists(fileName):
|
if not os.path.exists(fileName):
|
||||||
fileNameNotFound = False
|
fileNameNotFound = False
|
||||||
|
|
||||||
|
print()
|
||||||
print(f'Fájl mentése ide: {fileName}')
|
print(f'Fájl mentése ide: {fileName}')
|
||||||
print()
|
print()
|
||||||
|
|
||||||
# --------------------------------- Write xml -------------------------------- #
|
# ------------------------------- Generate xml ------------------------------- #
|
||||||
|
|
||||||
data = ET.Element('Leolvasasok')
|
data = ET.Element('Leolvasasok')
|
||||||
for mérő in allXmlData:
|
for mérő in allXmlData:
|
||||||
@@ -191,8 +196,18 @@ for mérő in allXmlData:
|
|||||||
a = ET.SubElement(currSub, adat)
|
a = ET.SubElement(currSub, adat)
|
||||||
a.text = mérő[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()
|
print()
|
||||||
|
|
||||||
tree = ET.ElementTree(data)
|
# --------------------------------- Save file -------------------------------- #
|
||||||
tree.write(fileName)
|
|
||||||
|
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