代码拉取完成,页面将自动刷新
import json
import os
from algoliasearch import algoliasearch
## Algolia Credentials
client = algoliasearch.Client("7EK9KHJW8M", os.environ['ALGOLIA_API_KEY'])
index = client.init_index('js_docs')
# get all plotly_js index files
indices = []
# array to fill with dictionaries of each file
all_js_files = []
for root, dirs, files in os.walk("_posts/plotly_js/", topdown=False):
for name in files:
if 'index' in name:
indices.append(os.path.join(root, name))
for i in range(len(indices)):
with open(indices[i]) as f:
file_content = f.readlines()
file_content = [x.strip() for x in file_content]
js_file = {}
for line in file_content:
if 'permalink' in line:
js_file['permalink']= line.split(': ')[1]
elif 'name' in line:
try:
js_file['name']= line.split(': ')[1]
except:
pass
elif 'description' in line:
try:
js_file['description']= line.split(': ')[1]
except:
pass
elif 'display_as' in line:
js_file['display_as']= line.split(': ')[1]
elif 'tags' in line:
js_file['tags']= line.split(': ')[1]
else:
pass
all_js_files.append(js_file)
## Send to Algolia
index.clear_index()
index.add_objects(all_js_files)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。