Skip to content

Commit f705c8b

Browse files
committed
WIP tutorial cell updater tool so that we can inject headers/footers
1 parent 254decf commit f705c8b

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tools/tutorial-cell-updater.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
3+
import nbformat
4+
import glob
5+
import logging
6+
import json
7+
logging.basicConfig(level=logging.INFO)
8+
9+
def update_notebook(fname):
10+
logging.info(f"Updating {fname}")
11+
12+
with open(fname) as f:
13+
nb = json.load(f)
14+
15+
cells = nb["cells"]
16+
17+
for cell in cells:
18+
print(list(cell.keys()))
19+
20+
with open(fname, "w") as wf:
21+
json.dump(nb, wf, indent=1, ensure_ascii=False)
22+
print(file=wf) # print final newline that jupyter adds apparently
23+
24+
if __name__ == "__main__":
25+
for fname in glob.glob("./tutorials/**/*.ipynb", recursive=True):
26+
update_notebook(fname)
27+
break

0 commit comments

Comments
 (0)