Commit c66b56c7 authored by Eric Duminil's avatar Eric Duminil
Browse files

Try to convert CSV to greendb.xml

parent 99e116a6
Showing with 37 additions and 0 deletions
+37 -0
from pathlib import Path
from dicttoxml import dicttoxml
from xml.dom.minidom import parseString
SCRIPT_DIR = Path(__file__).resolve().parent
INPUT_DIR = SCRIPT_DIR / 'input'
OUTPUT_DIR = SCRIPT_DIR / 'output'
OUTPUT_DIR.mkdir(exist_ok=True)
csv_path = INPUT_DIR / 'greendb_example.csv'
trees = []
db = {
'greenDatabase': {
'name': 'Gründatenbank Prototyp',
'description': f'Gründatenbank exported from {csv_path.name}',
'trees': trees
}
}
with open(csv_path) as csv:
for line in csv:
name, factor, *aliases = line.strip().split(';')
trees.append(
{'tree': {'name': name,
'speciesFactor': factor,
'aliases': [{'alias': alias} for alias in aliases]
}
}
)
xml = dicttoxml(db, attr_type=False, root=False)
dom = parseString(xml)
print(dom.toprettyxml())
Acer platanoides;0.5;Acer platanoides Columnare Ty;Acer platanoides Klimabaum;
Quercus robur;0.5;Blablabla;blabalblabal2;blabalblabal3
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment