def convert_notebooks(dirs): notebooks = [] for dir in dirs: for root, _, files in os.walk(dir): for file in files: if file.endswith('.ipynb'): notebooks.append(os.path.join(root, file)) exporter = MarkdownExporter() exporter.extra_template_basedirs.append(os.path.dirname(__file__)) exporter.template_name = 'ext_md' writer = writers.FilesWriter() for file in notebooks: convert_notebook(file, exporter=exporter, writer=writer)
raise ValueError( f"Specified location not '{path}'a file or directory.") # Go through all notebooks files in specified directory for file_loc in all_files: # Skip Modified files if "mod" in str(file_loc): continue # Skip checkpoints if ignore_checkpoints and ".ipynb_checkpoint" in str(file_loc): continue print(f"\033[1;33;40m \nProcessing file {file_loc}\033[0m") in_notebook = nbformat.read(str(file_loc), as_version=4) writer = writers.FilesWriter() if write_notebook: # Process the notebook to a new notebook (body, resources) = nb_exporter.from_notebook_node(in_notebook) # Write notebook file if overwrite_notebook: nb_file_loc = str(file_loc.with_suffix("")) else: nb_file_loc = str(file_loc.with_suffix(".mod")) print(f"Writing notebook to {nb_file_loc}.ipynb") writer.write(body, resources, nb_file_loc) if write_html: # Process the notebook to HTML