Clean Notebooks for publishing
Simple Notebook to clean notebook code cells.
import os
import json
notebooks = os.listdir()
for notebook in notebooks:
if 'Challenge' in notebook or 'Graph' in notebook:
print(notebook)
with open(notebook) as json_file:
data = json.load(json_file)
finalCellData = []
for cell in data['cells']:
if cell['cell_type'] == "code":
cell['source'] = cell['source'][0:2]
finalCellData.append(cell)
if cell['cell_type'] == 'markdown':
if "# Competition Unstructured Extension\n" in cell['source']:
break
data['cells'] = finalCellData
with open(notebook, 'w') as outfile:
json.dump(data, outfile)