Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mayer
CircularGreenSimCity
Commits
c66b56c7
Commit
c66b56c7
authored
Jul 23, 2024
by
Eric Duminil
Browse files
Try to convert CSV to greendb.xml
parent
99e116a6
Changes
2
Show whitespace changes
Inline
Side-by-side
python_scripts/csv_to_green_db/convert_to_greendb.py
0 → 100644
View file @
c66b56c7
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
())
python_scripts/csv_to_green_db/input/greendb_example.csv
0 → 100644
View file @
c66b56c7
Acer platanoides;0.5;Acer platanoides Columnare Ty;Acer platanoides Klimabaum;
Quercus robur;0.5;Blablabla;blabalblabal2;blabalblabal3
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment