-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathcsv2xrd.py
More file actions
executable file
·27 lines (22 loc) · 997 Bytes
/
csv2xrd.py
File metadata and controls
executable file
·27 lines (22 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python
import sys
from lxml import etree
ns = {None: "http://docs.oasis-open.org/ns/xri/xrd-1.0"}
xrds = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}XRDS", nsmap=ns)
with open(sys.argv[1]) as fd:
for line in fd:
line = line.strip()
e = [x.strip('"') for x in line.split(",")]
xrd = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}XRD", nsmap=ns)
xrds.append(xrd)
subject = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}Subject", nsmap=ns)
subject.text = e[3]
link = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}Link", nsmap=ns)
link.set('rel', "urn:oasis:names:tc:SAML:2.0:metadata")
link.set('href', e[3])
xrd.append(subject)
xrd.append(link)
title = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}Title", nsmap=ns)
title.text = e[1]
link.append(title)
print(etree.tostring(xrds, pretty_print=True))