Hi,
I'm trying to automatically export as html at the end of execution. (i.e. enter some parameters, 'run all' and have an html output).
From searching the group here, I came up with:
%%javascript
Jupyter.notebook.save_notebook();
Jupyter.notebook.kernel.execute("window_loc = '" + window.location + "'")
Jupyter.notebook.kernel.execute("notebook_base = '" + IPython.notebook.base_url + "'")
Jupyter.notebook.kernel.execute("notebook_path = '" + IPython.notebook.notebook_path + "'")
then on the next cell:
filename = 'outout.html'
from notebook.utils import url_path_join
import requests
scheme = requests.utils.urlparse(window_loc).scheme
netloc = requests.utils.urlparse(window_loc).netloc
base_url = requests.utils.urlunparse((scheme,netloc, '', '', '', ''))
url = url_path_join(base_url, 'nbconvert', 'html', notebook_base, notebook_path)
r = requests.request('GET', url, params={'download':True})
if r.status_code == 200:
with open(filename, 'wb') as f:
for chunk in r.iter_content(1024):
f.write(chunk)
they work okay when I execute one by one, but when I do 'run-all', it seems like the javascript ran async, so the next cell try to execute before it finishes saving and collecting the variables.
Any thoughts?
Cheers,
SL