-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.py
44 lines (34 loc) · 1.08 KB
/
generate.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
import json
def read_template():
with open("layout.json") as layout_f:
layout = json.load(layout_f)
with open("ixp_list.json") as ixplist_f:
ixplist = json.load(ixplist_f)
layout["ixp_list"] = ixplist
return layout
def if_only_dn42(m, l):
for c in m["connection_list"]:
if any(i['ixp_id'] == c["ixp_id"] for i in l["ixp_list"]):
return False
return True
def remove_dn42(m, l):
tmp = m["connection_list"]
m["connection_list"] = []
for c in tmp:
if any(i['ixp_id'] == c["ixp_id"] for i in l["ixp_list"]):
m["connection_list"].append(c)
return m
def generate():
g = requests.get(
"https://portal.ix42.org/api/v4/member-export/ixf/1.0?ignore_missing_ixfid=1")
j = g.json()
l = read_template()
l["timestamp"] = j["timestamp"]
for m in j["member_list"]:
if not if_only_dn42(m, l):
l["member_list"].append(remove_dn42(m, l))
with open("members.json", "w") as wf:
json.dump(l, wf, indent=4)
if __name__ == "__main__":
generate()