Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Martin Koehler
rdmo-catalog
Commits
88025df0
Commit
88025df0
authored
May 26, 2020
by
Jochen Klar
Browse files
Add to_csv.py tool
parent
718305cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
tools/to_csv.py
0 → 100755
View file @
88025df0
#!/usr/bin/env python3
import
argparse
import
csv
import
sys
import
xml.etree.ElementTree
as
et
nsmap
=
{
'dc'
:
'{http://purl.org/dc/elements/1.1/}'
}
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'file'
)
args
=
parser
.
parse_args
()
writer
=
csv
.
writer
(
sys
.
stdout
,
delimiter
=
','
,
quotechar
=
'"'
,
quoting
=
csv
.
QUOTE_MINIMAL
)
tree
=
et
.
parse
(
args
.
file
)
root
=
tree
.
getroot
()
for
child
in
root
:
uri
=
child
.
attrib
[
'{dc}uri'
.
format
(
**
nsmap
)]
row
=
[
uri
]
+
[
node
.
text
or
''
for
node
in
child
]
writer
.
writerow
(
row
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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