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
9 months ago
by
Eric Duminil
Browse files
Options
Download
Email Patches
Plain Diff
Try to convert CSV to greendb.xml
parent
99e116a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
python_scripts/csv_to_green_db/convert_to_greendb.py
+35
-0
python_scripts/csv_to_green_db/convert_to_greendb.py
python_scripts/csv_to_green_db/input/greendb_example.csv
+2
-0
python_scripts/csv_to_green_db/input/greendb_example.csv
with
37 additions
and
0 deletions
+37
-0
python_scripts/csv_to_green_db/convert_to_greendb.py
0 → 100644
+
35
-
0
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
())
This diff is collapsed.
Click to expand it.
python_scripts/csv_to_green_db/input/greendb_example.csv
0 → 100644
+
2
-
0
View file @
c66b56c7
Acer platanoides;0.5;Acer platanoides Columnare Ty;Acer platanoides Klimabaum;
Quercus robur;0.5;Blablabla;blabalblabal2;blabalblabal3
This diff is collapsed.
Click to expand it.
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