Skip to content

Commit

Permalink
修改了生成静态文件的代码
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lijin-THU committed Jan 6, 2016
1 parent 7d478fe commit 4462a45
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a49ab791807fec5418c683d58c4ad05b16485a10
c78cbd4dc66a20c38fbbee13e0394774c8cd2f18
84 changes: 84 additions & 0 deletions generate_static_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

# coding: utf-8

# # 将笔记转化为不同的文件格式

# In[1]:

import os
import os.path
import nbconvert


# 检查路径是否存在:

# In[2]:

if not os.path.exists('static files'):
os.mkdir('static files')


# 文件夹:

# In[3]:

folders = ['01. python tools',
'02. python essentials',
'03. numpy',
'04. scipy',
'05. advanced python',
'06. matplotlib',
'07. interfacing with other languages',
'08. object-oriented programming',
'09. theano',
'10. something interesting',
'11. useful tools'
]


# 遍历文件夹得到所有的文件名:

# In[4]:

file_names = []

for folder in folders:
files = sorted(os.listdir(folder))
file_names += [os.path.join(folder, file_name) for file_name in files if file_name.endswith('.ipynb')]


# In[5]:

def convert_to_files(names, to_format):
target_dir = os.path.join("static files", to_format)
for folder in folders:
if not os.path.exists(os.path.join(target_dir, folder)):
os.makedirs(os.path.join(target_dir, folder))
converter = {
"html": nbconvert.export_html,
"python": nbconvert.export_python
}

for file_name in names:
p = converter[to_format](file_name)
with open(os.path.join(target_dir, file_name[:-6] + p[1]["output_extension"]), 'w') as f:
f.write(p[0].encode("utf-8"))
print file_name


# 转化 HTML 文件:

# In[6]:

convert_to_files(file_names, "html")


# 产生新目录:

# In[7]:

with open('index.md') as f:
text = f.read()
with open(os.path.join("static files/html", "README.md"), "w") as g:
g.write(text.replace(".ipynb", ".html"))

2 changes: 1 addition & 1 deletion index.ipynb.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d2214383a9f3136d0f589b356aa5a23bdffb6ff2
faafe9dcbbf40e726159c852234725485d852b9f

0 comments on commit 4462a45

Please sign in to comment.