wip rewrite
This commit is contained in:
@@ -205,7 +205,7 @@ xmlString = ET.tostring(data, encoding="utf-8", xml_declaration=True)
|
||||
|
||||
# -------------------------------- Format xml -------------------------------- #
|
||||
|
||||
formatter = xmlformatter.Formatter(indent="2", indent_char=" ")
|
||||
formatter = xmlformatter.Formatter(indent=2, indent_char=" ")
|
||||
formattedXml = formatter.format_string(xmlString)
|
||||
|
||||
# print(formattedXml)
|
||||
|
||||
@@ -4,6 +4,7 @@ import argparse
|
||||
from importlib.metadata import metadata
|
||||
from pathlib import Path
|
||||
import csv
|
||||
import datetime
|
||||
|
||||
REQUIRED_CSV_COLUMNS = ['Notes', 'Meter n°', 'Reading', 'Reading data']
|
||||
|
||||
@@ -11,6 +12,7 @@ REQUIRED_CSV_COLUMNS = ['Notes', 'Meter n°', 'Reading', 'Reading data']
|
||||
METADATA = metadata("BudaportaFvmConvert")
|
||||
__version__ = METADATA["Version"]
|
||||
|
||||
|
||||
def run():
|
||||
parser = argparse.ArgumentParser(
|
||||
prog=METADATA["Name"],
|
||||
@@ -31,6 +33,7 @@ def run():
|
||||
args = parser.parse_args()
|
||||
|
||||
csvpaths = []
|
||||
readings = []
|
||||
|
||||
for path in args.source:
|
||||
if path.is_dir():
|
||||
@@ -39,8 +42,7 @@ def run():
|
||||
csvpaths.append(path)
|
||||
|
||||
for csvpath in csvpaths:
|
||||
CsvFile(csvpath)
|
||||
|
||||
readings.extend(CsvFile(csvpath).get_readings())
|
||||
|
||||
|
||||
def get_csv_paths(dp: Path):
|
||||
@@ -54,12 +56,42 @@ def get_csv_paths(dp: Path):
|
||||
|
||||
class CsvFile:
|
||||
def __init__(self, filepath: Path) -> None:
|
||||
with open(filepath, newline='') as csvfile:
|
||||
incsv = csv.reader(csvfile, delimiter=';')
|
||||
# csvArrs.append([])
|
||||
# for row in incsv:
|
||||
# csvArrs[0].append(row)
|
||||
self.header_numbers = {}
|
||||
self.readings = []
|
||||
with open(filepath, newline='', encoding="cp1252") as csvfile:
|
||||
incsv = list(csv.reader(csvfile, delimiter=';'))
|
||||
header_row = incsv.pop(0)
|
||||
for i, col_name in enumerate(header_row):
|
||||
if col_name in REQUIRED_CSV_COLUMNS:
|
||||
self.header_numbers[col_name] = i
|
||||
for csv_row in incsv:
|
||||
self.readings.append(Reading(csv_row, self.header_numbers))
|
||||
|
||||
class CsvRow:
|
||||
def __init__(self, ) -> None:
|
||||
pass
|
||||
def get_readings(self) -> list["Reading"]:
|
||||
return self.readings
|
||||
|
||||
class Reading:
|
||||
def __init__(self, csv_row: list, header_numbers: dict) -> None:
|
||||
self.data_dict = {
|
||||
"KeszulekAzon": "",
|
||||
"Gyariszam": "",
|
||||
"MeroAllas": "",
|
||||
"MertekEgyseg": "m3",
|
||||
"LeoMod": "20",
|
||||
"LeoMegjegyzes": "06",
|
||||
"TenyLeoDatum": "",
|
||||
"TenyLeoIdo": ""
|
||||
}
|
||||
for col_name, col_num in header_numbers.items():
|
||||
if col_name == "Notes":
|
||||
self.data_dict["KeszulekAzon"] = csv_row[col_num]
|
||||
elif col_name == "Meter n°":
|
||||
self.data_dict["Gyariszam"] = csv_row[col_num]
|
||||
elif col_name == "Reading":
|
||||
self.data_dict["MeroAllas"] = csv_row[col_num]\
|
||||
.replace(',', '.').replace(' ', '')
|
||||
elif col_name == "Reading data":
|
||||
reading_date = datetime.datetime.strptime(
|
||||
csv_row[col_num], '%d. %m. %Y %H:%M:%S')
|
||||
self.data_dict["TenyLeoDatum"] = reading_date.strftime('%Y%m%d')
|
||||
self.data_dict["TenyLeoIdo"] = reading_date.strftime('%H%M%S')
|
||||
|
||||
Reference in New Issue
Block a user