|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": 1, |
| 5 | + "execution_count": 35, |
6 | 6 | "metadata": {},
|
7 |
| - "outputs": [], |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "name": "stdout", |
| 10 | + "output_type": "stream", |
| 11 | + "text": [ |
| 12 | + "1816 1783\n" |
| 13 | + ] |
| 14 | + } |
| 15 | + ], |
8 | 16 | "source": [
|
| 17 | + "import os\n", |
9 | 18 | "import yaml\n",
|
10 | 19 | "\n",
|
11 | 20 | "#all_posts.txt is generated with the following command from the repo's root directory:\n",
|
12 | 21 | "# $ find `pwd`/_posts -type f > all_posts.txt\n",
|
13 | 22 | "\n",
|
| 23 | + "cwd = os.getcwd()\n", |
| 24 | + "docs_path = os.path.split(cwd)[0]\n", |
| 25 | + "\n", |
14 | 26 | "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", |
16 | 28 | " file_names = [line.split('\\n')[0] for line in f]\n",
|
17 | 29 | "\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", |
19 | 32 | "\n",
|
20 | 33 | "def get_file(n):\n",
|
21 | 34 | " py_file = []\n",
|
|
44 | 57 | "files = [get_file(n) for n in html]\n",
|
45 | 58 | "names = [(n,get_name(f)) for f,n in files if get_name(f)]\n",
|
46 | 59 | "\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", |
48 | 61 | "c = [n[1] for n in names]\n",
|
49 | 62 | "print(len(c),len(set(c)))\n",
|
50 | 63 | "\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", |
52 | 65 | "\n",
|
53 | 66 | "git_data = get_git_data(names)\n",
|
54 | 67 | "\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", |
56 | 69 | " yaml.dump(git_data, outfile, default_flow_style=False)"
|
57 | 70 | ]
|
58 | 71 | }
|
|
0 commit comments