1 Star 0 Fork 0

沉默老妖/graphing-library-docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
update_js_docs_search.py 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
Joseph Damiba 提交于 2020-01-28 12:33 . initial repo setup
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)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/coolyaolei/graphing-library-docs.git
git@gitee.com:coolyaolei/graphing-library-docs.git
coolyaolei
graphing-library-docs
graphing-library-docs
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385