(pre_examples_content, parsed_json, post_examples_content)
| 269 | |
| 270 | |
| 271 | def convert_to_notebook(pre_examples_content, parsed_json, post_examples_content): |
| 272 | result = { |
| 273 | "cells": [], |
| 274 | "metadata": {}, |
| 275 | "nbformat": 4, |
| 276 | "nbformat_minor": 2 |
| 277 | } |
| 278 | |
| 279 | notebook_path = "wtf.ipynb" |
| 280 | |
| 281 | result["cells"] += convert_to_cells([generate_markdown_block(pre_examples_content)], False) |
| 282 | |
| 283 | for example in parsed_json: |
| 284 | parts = example["parts"] |
| 285 | build_up = parts.get("build_up") |
| 286 | explanation = parts.get("explanation") |
| 287 | read_only = example.get("read_only") |
| 288 | |
| 289 | if build_up: |
| 290 | result["cells"] += convert_to_cells(build_up, read_only) |
| 291 | |
| 292 | if explanation: |
| 293 | result["cells"] += convert_to_cells(explanation, read_only) |
| 294 | |
| 295 | result["cells"] += convert_to_cells([generate_markdown_block(post_examples_content)], False) |
| 296 | |
| 297 | #pprint.pprint(result, indent=2) |
| 298 | with open(notebook_path, "w") as f: |
| 299 | json.dump(result, f) |
| 300 | |
| 301 | |
| 302 | with open(fpath, 'r+', encoding="utf-8") as f: |
no test coverage detected