Skip to content

Commit c790fee

Browse files
committed
Add script for converting notebooks to html
1 parent 906ba36 commit c790fee

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

scripts/notebook_to_html.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from pathlib import Path
2+
import subprocess
3+
import sys
4+
5+
6+
def main():
7+
path = sys.argv[1]
8+
if path.strip().lower() == "all":
9+
convert_all_notebooks_to_html()
10+
else:
11+
convert_notebook_to_html(path)
12+
13+
14+
def convert_all_notebooks_to_html():
15+
notebook_dir = Path(__file__).parent.parent / "notebooks"
16+
for directory in (
17+
notebook_dir / "beginner" / "notebooks",
18+
notebook_dir / "intermediate" / "notebooks",
19+
):
20+
for notebook_path in directory.glob("*.ipynb"):
21+
convert_notebook_to_html(notebook_path)
22+
23+
24+
def convert_notebook_to_html(notebook_path):
25+
path = Path(notebook_path)
26+
if not path.exists():
27+
raise SystemExit(f"Invalid path {path}")
28+
29+
output_dir = path.parent.parent / "html"
30+
31+
cmd = f"jupyter nbconvert --to html --execute --ExecutePreprocessor.timeout=30 --output-dir {output_dir} {path.absolute()}"
32+
subprocess.check_call(cmd.split())
33+
34+
35+
if __name__ == "__main__":
36+
main()

0 commit comments

Comments
 (0)