Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eduGAIN contacts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
edugain
eduGAIN contacts
Merge requests
!2
Updated edugain_contacts.py
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Updated edugain_contacts.py
Romain.Wartel/edugain-contacts:patch-1
into
master
Overview
1
Commits
1
Pipelines
0
Changes
1
Closed
Romain Wartel
requested to merge
Romain.Wartel/edugain-contacts:patch-1
into
master
4 years ago
Overview
1
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
33433812
1 commit,
4 years ago
1 file
+
36
−
8
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
edugain_contacts.py
+
36
−
8
Options
@@ -2,25 +2,49 @@
@@ -2,25 +2,49 @@
# This script will download the current edugain metadata aggregate XML
# This script will download the current edugain metadata aggregate XML
# and parse it to derive a list of contacts in CSV format.
# and parse it to derive a list of contacts in CSV format.
# This list will be printed to stdout.
# This list will be printed to contacts/edugain.csv.
# It first reads all files in the contacts directory to see which contacts
# already exist, as they will be of better quality than the ones in the XML.
import
requests
import
requests
import
sys
import
glob
import
os.path
from
xml.etree
import
ElementTree
as
ET
from
xml.etree
import
ElementTree
as
ET
from
urllib.parse
import
urlparse
from
urllib.parse
import
urlparse
def
strip_start
(
s
,
start
):
if
len
(
sys
.
argv
)
!=
2
:
if
s
.
startswith
(
start
):
print
(
'
Please run as: {} <contacts_dir>
'
.
format
(
sys
.
argv
[
0
]))
return
s
[
len
(
start
):]
sys
.
exit
(
1
)
return
s
print
(
'
Downloading XML from edugain...
'
)
xml_req
=
requests
.
get
(
'
https://mds.edugain.org/edugain-v1.xml
'
)
xml_req
=
requests
.
get
(
'
https://mds.edugain.org/edugain-v1.xml
'
)
root
=
ET
.
fromstring
(
xml_req
.
content
)
root
=
ET
.
fromstring
(
xml_req
.
content
)
contacts
=
set
()
contacts
=
set
()
seen_doms
=
set
()
seen_doms
=
set
()
contacts_dir
=
sys
.
argv
[
1
]
for
cf
in
glob
.
glob
(
os
.
path
.
join
(
contacts_dir
,
'
*
'
)):
if
os
.
path
.
basename
(
cf
)
==
'
edugain.csv
'
:
continue
with
open
(
cf
,
'
r
'
)
as
f
:
for
l
in
f
.
readlines
():
parts
=
l
.
split
(
'
,
'
)
if
parts
:
seen_doms
.
add
(
parts
[
0
])
print
(
'
Excluding {} domains that are in other contact CSVs
'
.
format
(
len
(
seen_doms
)))
def
strip_start
(
s
,
start
):
if
s
.
startswith
(
start
):
return
s
[
len
(
start
):]
return
s
ns
=
{
ns
=
{
'
md
'
:
'
urn:oasis:names:tc:SAML:2.0:metadata
'
,
'
md
'
:
'
urn:oasis:names:tc:SAML:2.0:metadata
'
,
'
mdui
'
:
'
urn:oasis:names:tc:SAML:metadata:ui
'
,
'
mdui
'
:
'
urn:oasis:names:tc:SAML:metadata:ui
'
,
@@ -64,5 +88,9 @@ for entity in entities:
@@ -64,5 +88,9 @@ for entity in entities:
seen_doms
.
add
(
domain_text
)
seen_doms
.
add
(
domain_text
)
contacts
.
add
(
'
{},{},{}
'
.
format
(
domain_text
,
contact_txt
,
orgname
))
contacts
.
add
(
'
{},{},{}
'
.
format
(
domain_text
,
contact_txt
,
orgname
))
for
contact
in
sorted
(
contacts
):
outpath
=
os
.
path
.
join
(
contacts_dir
,
'
edugain.csv
'
)
print
(
contact
)
print
(
'
Writing {} contacts to {}
'
.
format
(
len
(
contacts
),
outpath
))
with
open
(
outpath
,
'
w
'
)
as
fout
:
fout
.
write
(
'
domain,contact,name
\n\n
'
)
for
contact
in
sorted
(
contacts
):
fout
.
write
(
contact
+
'
\n
'
)
\ No newline at end of file
Loading