Skip to content

Commit

Permalink
run_all_jupyter_notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
omartinsky committed Apr 30, 2017
1 parent 4b627f0 commit 45a9c33
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions __run_all_jupyter_notebooks.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
import sys
import sys, os
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
from nbconvert import HTMLExporter

def tohtml(input, output=None):
if output is None:
output = input + ".html"
def tohtml(working_directory, input, output=None):
prevcwd = os.getcwd()
try:
os.chdir(working_directory)

if output is None:
output = input + ".html"

print("Converting %s --> %s" % (input, output))
ep = ExecutePreprocessor(timeout=300, kernel_name='python3')
print("Converting %s --> %s" % (input, output))
ep = ExecutePreprocessor(timeout=300, kernel_name='python3')

with open(input) as f:
nb = nbformat.read(f, as_version=4)

ep.preprocess(nb, {'metadata': {'path': './'}})
with open(input) as f:
nb = nbformat.read(f, as_version=4)
ep.preprocess(nb, {'metadata': {'path': './'}})

#filename_output = input + ".executed.ipynb"
#with open(filename_output, 'wt') as f:
# nbformat.write(nb, f)
#filename_output = input + ".executed.ipynb"
#with open(filename_output, 'wt') as f:
# nbformat.write(nb, f)

exportHTML = HTMLExporter()
(body, resources) = exportHTML.from_notebook_node(nb)
exportHTML = HTMLExporter()
(body, resources) = exportHTML.from_notebook_node(nb)

with open(output, 'wt') as f:
f.write(body)

print("Done")
with open(output, 'wt') as f:
f.write(body)

print("Done")
finally:
os.chdir(prevcwd)


tohtml("binomial_option_pricing/binomial_option_pricing.ipynb")
tohtml("black_litterman/black_litterman.ipynb")
tohtml("binomial_option_pricing", "binomial_option_pricing.ipynb")
tohtml("black_litterman", "black_litterman.ipynb")

0 comments on commit 45a9c33

Please sign in to comment.