Skip to content

Commit 3918bf7

Browse files
committed
make update script os agnostic
1 parent a8bb188 commit 3918bf7

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

scripts/update github.ipynb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,33 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": 35,
66
"metadata": {},
7-
"outputs": [],
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"1816 1783\n"
13+
]
14+
}
15+
],
816
"source": [
17+
"import os\n",
918
"import yaml\n",
1019
"\n",
1120
"#all_posts.txt is generated with the following command from the repo's root directory:\n",
1221
"# $ find `pwd`/_posts -type f > all_posts.txt\n",
1322
"\n",
23+
"cwd = os.getcwd()\n",
24+
"docs_path = os.path.split(cwd)[0]\n",
25+
"\n",
1426
"file_names = []\n",
15-
"with open('../all_posts.txt') as f:\n",
27+
"with open(os.path.join(docs_path,'all_posts.txt')) as f:\n",
1628
" file_names = [line.split('\\n')[0] for line in f]\n",
1729
"\n",
18-
"html = list(filter(lambda x: '.html' in x,file_names))\n",
30+
"no_swp = list(filter(lambda x: '.swp' not in x,file_names))\n",
31+
"html = list(filter(lambda x: '.html' in x,no_swp))\n",
1932
"\n",
2033
"def get_file(n):\n",
2134
" py_file = []\n",
@@ -44,15 +57,15 @@
4457
"files = [get_file(n) for n in html]\n",
4558
"names = [(n,get_name(f)) for f,n in files if get_name(f)]\n",
4659
"\n",
47-
"#make sure that most names are unique\n",
60+
"#make sure that most names are unique so that we know we have few as 404s as possible\n",
4861
"c = [n[1] for n in names]\n",
4962
"print(len(c),len(set(c)))\n",
5063
"\n",
51-
"get_git_data = lambda names: {n.split('name: ')[1]: 'https://github.com/plotly/documentation/tree/source-design-merge/' + '/'.join(loc.split('/home/michael/plotly/repos/documentation/')[1].split('/')[0:-1]) for loc,n in names}\n",
64+
"get_git_data = lambda names: {n.split('name: ')[1]: 'https://github.com/plotly/documentation/tree/source-design-merge/' + '/'.join(loc.split(docs_path)[1].split('/')[0:-1]) for loc,n in names}\n",
5265
"\n",
5366
"git_data = get_git_data(names)\n",
5467
"\n",
55-
"with open('../_data/git_url.yml', 'w') as outfile:\n",
68+
"with open(os.path.join(docs_path,'_data','git_url.yml'), 'w') as outfile:\n",
5669
" yaml.dump(git_data, outfile, default_flow_style=False)"
5770
]
5871
}

0 commit comments

Comments
 (0)