Add script for converting notebooks to html
This commit is contained in:
36
scripts/notebook_to_html.py
Normal file
36
scripts/notebook_to_html.py
Normal file
@@ -0,0 +1,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()
|
||||
Reference in New Issue
Block a user