forked from jerry-git/learn-python3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotebook_to_html.py
More file actions
36 lines (26 loc) · 966 Bytes
/
notebook_to_html.py
File metadata and controls
36 lines (26 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from pathlib import Path
import subprocess
import sys
def main():
path = sys.argv[1]
if path.strip().lower() == "all":
convert_all_notebooks_to_html()
else:
convert_notebook_to_html(path)
def convert_all_notebooks_to_html():
notebook_dir = Path(__file__).parent.parent / "notebooks"
for directory in (
notebook_dir / "beginner" / "notebooks",
notebook_dir / "intermediate" / "notebooks",
):
for notebook_path in directory.glob("*.ipynb"):
convert_notebook_to_html(notebook_path)
def convert_notebook_to_html(notebook_path):
path = Path(notebook_path)
if not path.exists():
raise SystemExit(f"Invalid path {path}")
output_dir = path.parent.parent / "html"
cmd = f"jupyter nbconvert --to html --execute --ExecutePreprocessor.timeout=30 --output-dir {output_dir} {path.absolute()}"
subprocess.check_call(cmd.split())
if __name__ == "__main__":
main()