Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ethen8181
GitHub Repository: ethen8181/machine-learning
Path: blob/master/convert_to_html.py
1461 views
1
"""
2
Based on the location of this script, recursively convert all
3
jupyter notebooks to html file.
4
Potential use case is to host these static html file on
5
github pages or else where.
6
7
Examples
8
--------
9
python convert_to_html.py
10
11
References
12
----------
13
Rendering Jupyter Notebooks (IPython Notebook) on Github Pages Sites
14
- http://notesofaprogrammer.blogspot.com/2017/02/rendering-jupyter-notebooks-ipython.html
15
"""
16
import os
17
from subprocess import call
18
19
20
def main(base_dir):
21
convert_to_html_command = 'jupyter nbconvert --to html --template full {}'
22
23
for root_dir, sub_dir, filenames in os.walk(base_dir):
24
# ignore notebook checkpoints
25
if '.ipynb_checkpoints' in root_dir:
26
continue
27
28
for filename in filenames:
29
_, file_extension = os.path.splitext(filename)
30
if file_extension == '.ipynb':
31
notebook_path = os.path.join(root_dir, filename)
32
call(convert_to_html_command.format(notebook_path), shell=True)
33
34
35
if __name__ == '__main__':
36
# we can modify this argument to only scan some sub-folders
37
base_dir = '.'
38
main(base_dir)
39
40