-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_notebooks.py
37 lines (25 loc) · 931 Bytes
/
run_notebooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from os import chdir, path
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
def run_notebook(nb_path):
'''run_notebook(str)
nb_path: notebook path
return: None'''
print(f"\nRunning {nb_path} ...")
# open the notebook
with open(nb_path, encoding="utf-8") as fp:
nb = nbformat.read(fp, as_version=4)
# execute the notebook
abs_path = path.dirname(path.realpath(nb_path))
ep = ExecutePreprocessor(timeout=600, kernel_name="python3")
ep.preprocess(nb, {"metadata": {"path": abs_path}})
# update the notebook
with open(nb_path, "w", encoding="utf-8") as fp:
nbformat.write(nb, fp)
# Set work directory for the script
scriptpath = path.dirname(path.realpath(__file__))
chdir(scriptpath)
# Finally, update notebooks/results
notebooks = ["COVID/01_Vax_vs_Deaths_Biv_Map_Basemap.ipynb"]
for notebook in notebooks:
run_notebook(notebook)