forked from plotly/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_ref_search.py
182 lines (169 loc) · 10.4 KB
/
update_ref_search.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import json
import os
from algoliasearch import algoliasearch
## Algolia Credentials
client = algoliasearch.Client("7EK9KHJW8M", os.environ['ALGOLIA_API_KEY'])
index = client.init_index('schema')
## Load plotschema.json
# Note _data/plotschema.json is updated upon each deploy
p = json.load(open('_data/plotschema.json'))
schema = []
## Data Level 1: Traces
# Add trace dictionaries to schema array.
# The trace dictionary include name: trace name, permalink: reference/#trace-name, and description if applicable.
for i in p['schema']['traces']:
trace = {}
trace ['name'] = i
trace ['permalink'] = 'reference/#'+i
if p['schema']['traces'][i]['meta']:
trace ['description'] = (p['schema']['traces'][i]['meta']['description']).replace('*', '"')
else: pass
schema.append(trace)
## Data Level 2: Nested Attributes
for i in p['schema']['traces']:
for att1 in p['schema']['traces'][i]['attributes']:
if not any(value in att1 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
try:
attribute = {}
attribute ['name'] = i+' > '+att1
attribute ['permalink'] = 'reference/#'+i+'-'+att1
attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = i+' > '+att1
attribute ['permalink'] = 'reference/#'+i+'-'+att1
attribute ['description'] = 'Properties for '+att1
schema.append(attribute)
for att2 in p['schema']['traces'][i]['attributes'][att1]:
if not any(value in att2 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
try:
if isinstance(p['schema']['traces'][i]['attributes'][att1][att2], dict):
try:
attribute = {}
attribute ['name'] = i+' > '+att1+' > '+att2
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2
attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1][att2]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = i+' > '+att1+' > '+att2
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2
attribute ['description'] = 'Properties for '+att2
schema.append(attribute)
except:
pass
try:
for att3 in p['schema']['traces'][i]['attributes'][att1][att2]:
if not any(value in att3 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
try:
if isinstance(p['schema']['traces'][i]['attributes'][att1][att2][att3], dict):
try:
attribute = {}
attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3
attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1][att2][att3]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3
attribute ['description'] = 'Properties for '+att3
schema.append(attribute)
except:
pass
try:
for att4 in p['schema']['traces'][i]['attributes'][att1][att2][att3]:
if not any(value in att4 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
try:
if isinstance(p['schema']['traces'][i]['attributes'][att1][att2][att3][att4], dict):
try:
attribute = {}
attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3+' > '+att4
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3+'-'+att4
attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1][att2][att3][att4]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3+' > '+att4
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3+'-'+att4
attribute ['description'] = 'Properties for '+att4
schema.append(attribute)
except:
pass
except:
pass
except:
pass
## Layout Attributes
for att1 in p['schema']['layout']['layoutAttributes']:
if not any(value in att1 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
try:
attribute = {}
attribute ['name'] = 'Layout > '+att1
attribute ['permalink'] = 'reference/#layout-'+att1
attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = 'Layout > '+att1
attribute ['permalink'] = 'reference/#layout-'+att1
attribute ['description'] = 'Properties for '+att1
schema.append(attribute)
for att2 in p['schema']['layout']['layoutAttributes'][att1]:
if not any(value in att2 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
try:
if isinstance(p['schema']['layout']['layoutAttributes'][att1][att2], dict):
try:
attribute = {}
attribute ['name'] = 'Layout > '+att1+' > '+att2
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2
attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1][att2]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = 'Layout > '+att1+' > '+att2
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2
attribute ['description'] = 'Properties for '+att2
schema.append(attribute)
except:
pass
try:
for att3 in p['schema']['layout']['layoutAttributes'][att1][att2]:
if not any(value in att3 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
if isinstance(p['schema']['layout']['layoutAttributes'][att1][att2][att3], dict):
try:
attribute = {}
attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3
attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1][att2][att3]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3
attribute ['description'] = 'Properties for '+att3
schema.append(attribute)
try:
for att4 in p['schema']['layout']['layoutAttributes'][att1][att2][att3]:
if not any(value in att4 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
if isinstance(p['schema']['layout']['layoutAttributes'][att1][att2][att3][att4], dict):
try:
attribute = {}
attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3+' > '+att4
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3+'-'+att4
attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1][att2][att3][att4]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3+' > '+att4
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3+'-'+att4
attribute ['description'] = 'Properties for '+att4
schema.append(attribute)
except:
pass
except:
pass
## Send to Algolia
index.clear_index()
index.add_objects(schema)