import json import argparse from docx import Document from typing import Dict, List def…
- User
import json import argparse from docx import Document from typing import Dict, List
def read_notebook(path: str) -> Dict: with open(path, encoding='utf8') as f: file = json.load(f) return file
def parse_notebook(file: Dict) -> Document: document = Document() for cell in file['cells']: if cell['cell_type'] == 'markdown': paragraph = parse_cell(cell['source']) document.add_paragraph(paragraph) return document
def parse_cell(lines: List) -> str: paragraph = '' for line in lines: if "![" not in line: # drop pictures paragraph += line return paragraph
def main(): parser = argparse.ArgumentParser(description='Process command line arguments.') parser.add_argument('--path', type=str, help='notebook path for parsing') args = parser.parse_args() path = args.path
file = read_notebook(path) document = parse_notebook(file) document.save('docx_file.docx')if name == "main": main()
- Assistant
The provided code is a Python script that converts a Jupyter Notebook (in JSON format) to a Word document (in DOCX format). It uses the
jsonmodule to read the notebook file,argparseto manage command-line arguments,python-docxto handle the DOCX file creation, andtypingfor type annotations.Let's break down the script's functionality:
- User
create short description for github readme with fast start section
- Assistant
Jupyter to DOCX Converter
This Python utility converts Jupyter Notebooks (
.ipynb) into Microsoft Word Documents (.docx). Ideal for those who need to share their notebooks in a universally readable format without running a Jupyter server.Quick Start
- Clone the repository:
git clone https://github.com/your-repository/jupyter-to-docx.git cd jupyter-to-docx- Install the required dependencies:
pip install -r requirements.txt- Convert a Jupyter Notebook to DOCX by running:
python jupyter_to_docx.py --path path_to_your_notebook.ipynbA new Word document
docx_file.docxwill be created in the current directory containing the markdown content from your Jupyter Notebook. - User
add formationg
- Assistant
Jupyter to DOCX Converter 📘🔀
Transform your Jupyter Notebooks (
.ipynb) into sleek Microsoft Word Documents (.docx). Great for academics, data scientists, and anyone looking to present their Jupyter notebooks in a familiar and professional format.Quick Start 🚀
Ready to convert your notebooks with minimal setup? Follow these steps:
1. Clone the Repository
Open your terminal or command prompt and run:
git clone https://github.com/your-username/jupyter-to-docx.git cd jupyter-to-docx2. Install Dependencies
Ensure that Python and
pipare already installed on your system, then execute:pip install -r requirements.txt3. Convert Your Notebook
Now it's time to turn that notebook into a doc:
python jupyter_to_docx.py --path /path/to/your/notebook.ipynbVoilà! 🌟 Look for
docx_file.docxin your current folder and behold your Jupyter Notebook as a Word document.
For additional options and further customization, refer to the full usage documentation below. Happy converting!