forked from IdentityPython/pyFF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv2xrd.py
executable file
·28 lines (23 loc) · 979 Bytes
/
csv2xrd.py
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
28
#!/usr/bin/env python
import io
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 io.open(sys.argv[1]) as fd:
for l in fd.readlines():
l = l.strip()
e = [x.strip('"') for x in l.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)