Skip to content

Commit 4462a45

Browse files
committed
修改了生成静态文件的代码
Former-commit-id: 8c96c50 Former-commit-id: fc9f5a18ba5f6352607d6d4dc43b6b44df0582a2 [formerly 0a9523d4a7a7b4c4d21cf0f8d291d02e2f9b9abb] [formerly e6dfbe363acc68ada52545cb91c1a78730b11906 [formerly d54946670050a8122e4e150eb9444e51df18477c]] [formerly b57096490fc65880afb7b5aa603161b475608ce3 [formerly cd6d3f7f675ecbbd2c4c579621f492b7f4b580fa] [formerly dac4f4af0ef63f056e4a99245573058f8c9df92c [formerly 8d893ef8a091884c6d95deda653f70649299cbc1]]] [formerly eea03e1eb6224f532b10285230b179e83417c352 [formerly cd5f79bc29c0a071c5109d6cb5e9225fe9b90bec] [formerly 0bb3c473b362644f7d32d0be3282d26281231ce5 [formerly 4a38074749ded9db7bf91ae5ca9947ea5e4dabca]] [formerly b10213ca5ff6d5a358076adba3a10aa63492a4db [formerly 0d27a3c9a95ab5c7f5e9fe76b13f4fa67952d7bf] [formerly d74eace290b4588130b8460363c6d3c99076e9b4 [formerly 70cfe2e]]]] Former-commit-id: 7b5df348765dcaf0c71f5908c9fdb083c869d29e [formerly cdf63fd811034885e702208bc1d031b5399f7943] [formerly 00d823db6d042de8fa3762c67adc73faf29e288f [formerly c4de4c3d8d9b29da9133f8dc9bc11103a8d3b934]] [formerly 208554931f19e6bf633f7ebfb4b7223e8e1636ce [formerly fc391edd6c7db8d350752ac3d6836904b90c3c6a] [formerly 2b6ff49e6b1f4a8cffda03a8dcce92e849dfb6e9 [formerly b58e5275008bd99f7fa9bb269a400f0e26541709]]] Former-commit-id: e9089958c6d15add7e4bb9c1f1eca7f66db35372 [formerly 1a071a70f09f4a6e31805a68ece4286fd3429f6f] [formerly 08bdc7daf9d266a53292225bca4d502504c805bd [formerly a7ef70f2cccd3619f61f1bc1308161e78569f1ff]] Former-commit-id: b442ac64557715c584c347139a26127c6ff0f81d [formerly 0eca5ee889564fab75a8ab4e1b9db5e0fc56d0f0] Former-commit-id: 8043eb8a6f9630f4e3f891d87d25a74a0aa2b53d
1 parent 7d478fe commit 4462a45

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

README.md.REMOVED.git-id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a49ab791807fec5418c683d58c4ad05b16485a10
1+
c78cbd4dc66a20c38fbbee13e0394774c8cd2f18

generate_static_files.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
# coding: utf-8
3+
4+
# # 将笔记转化为不同的文件格式
5+
6+
# In[1]:
7+
8+
import os
9+
import os.path
10+
import nbconvert
11+
12+
13+
# 检查路径是否存在:
14+
15+
# In[2]:
16+
17+
if not os.path.exists('static files'):
18+
os.mkdir('static files')
19+
20+
21+
# 文件夹:
22+
23+
# In[3]:
24+
25+
folders = ['01. python tools',
26+
'02. python essentials',
27+
'03. numpy',
28+
'04. scipy',
29+
'05. advanced python',
30+
'06. matplotlib',
31+
'07. interfacing with other languages',
32+
'08. object-oriented programming',
33+
'09. theano',
34+
'10. something interesting',
35+
'11. useful tools'
36+
]
37+
38+
39+
# 遍历文件夹得到所有的文件名:
40+
41+
# In[4]:
42+
43+
file_names = []
44+
45+
for folder in folders:
46+
files = sorted(os.listdir(folder))
47+
file_names += [os.path.join(folder, file_name) for file_name in files if file_name.endswith('.ipynb')]
48+
49+
50+
# In[5]:
51+
52+
def convert_to_files(names, to_format):
53+
target_dir = os.path.join("static files", to_format)
54+
for folder in folders:
55+
if not os.path.exists(os.path.join(target_dir, folder)):
56+
os.makedirs(os.path.join(target_dir, folder))
57+
converter = {
58+
"html": nbconvert.export_html,
59+
"python": nbconvert.export_python
60+
}
61+
62+
for file_name in names:
63+
p = converter[to_format](file_name)
64+
with open(os.path.join(target_dir, file_name[:-6] + p[1]["output_extension"]), 'w') as f:
65+
f.write(p[0].encode("utf-8"))
66+
print file_name
67+
68+
69+
# 转化 HTML 文件:
70+
71+
# In[6]:
72+
73+
convert_to_files(file_names, "html")
74+
75+
76+
# 产生新目录:
77+
78+
# In[7]:
79+
80+
with open('index.md') as f:
81+
text = f.read()
82+
with open(os.path.join("static files/html", "README.md"), "w") as g:
83+
g.write(text.replace(".ipynb", ".html"))
84+

index.ipynb.REMOVED.git-id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d2214383a9f3136d0f589b356aa5a23bdffb6ff2
1+
faafe9dcbbf40e726159c852234725485d852b9f

0 commit comments

Comments
 (0)