-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_index.py
71 lines (64 loc) · 1.66 KB
/
create_index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
import json
import requests
res = requests.get(
"https://api.dart.dev/stable/3.2.6/index.json"
) # official Dart docs index; currently contains about 12.75k indices
if res.ok:
data = res.json()
# filters with weights
filters = {
"library": 2,
"class": 2,
"mixin": 3,
"extension": 3,
"typedef": 3,
"method": 4,
"accessor": 4,
"operator": 4,
"constant": 4,
"property": 4,
"constructor": 4,
"top-level property": 5,
"function": 5,
"enum": 5,
"top-level constant": 5,
}
# index of kinds
kinds = {
0: "accessor",
1: "constant",
2: "constructor",
3: "class",
4: "dynamic",
5: "enum",
6: "extension",
7: "function",
8: "library",
9: "method",
10: "mixin",
11: "Never",
12: "package",
13: "parameter",
14: "prefix",
15: "property",
16: "SDK",
17: "topic",
18: "top-level constant",
19: "top-level property",
20: "typedef",
21: "type parameter",
}
index = []
for el in data:
if "kind" in el and el["kind"] in kinds:
el["type"] = kinds[el["kind"]]
el["weight"] = el["kind"]
del el["kind"]
if "enclosedBy" in el:
if "kind" in el["enclosedBy"]:
el["enclosedBy"]["type"] = kinds[el["enclosedBy"]["kind"]]
del el["enclosedBy"]["kind"]
index.append(el)
with open("index.json", "w") as out_fh:
json.dump(index, out_fh)