MCPcopy
hub / github.com/satwikkansal/wtfpython / convert_to_notebook

Function convert_to_notebook

irrelevant/notebook_generator.py:271–299  ·  view source on GitHub ↗
(pre_examples_content, parsed_json, post_examples_content)

Source from the content-addressed store, hash-verified

269
270
271def 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
302with open(fpath, 'r+', encoding="utf-8") as f:

Callers 1

Calls 2

convert_to_cellsFunction · 0.85
generate_markdown_blockFunction · 0.85

Tested by

no test coverage detected