1

I have a Python/Pandas script that will generate some reports I would like. Currently, NBConvert will always save the file as the title of my iPython notebook. Ideally, were my report on the subject of cars I would like a [Ferrari, Ford, Tesla,...] report each saved under their respective company names [Ferrari.html, Ford.html, Tesla.html,...]. Importantly, this is all created from one notebook "Car_Data.ipynb".

I have read the documentation here: NBConvert Documentation

This notes that: "The output file created by nbconvert will have the same base name as the notebook and will be placed in the current working directory."

Does anyone know of a way to script this type of HTML output from an iPython notebook.

Currently, I have implemented the code below which saves the current notebook under the current filename:

#This is a script sourced from: http://stackoverflow.com/questions/19067822/save-ipython-notebook-as-script-programmatically to save our notebook as HTML
try :
    if(__IPYTHON__) :
        !ipython nbconvert --to html Cluster_Availability_Charts.ipynb;
except NameError :
    pass

Thank you for the assistance!

Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234
um8ra
  • 185
  • 2
  • 12

2 Answers2

1

Here is how to insert your own filename and save the notebook using iPython + NBConvert:

#This is a script sourced from: http://stackoverflow.com/questions/19067822/save-ipython-notebook-as-script-programmatically to save our notebook as HTML
prefix = u'ipython nbconvert --to html --output ' #Trailing space needed
mystr = u'filename_without_html ' #Trailing space needed
suffix = u'My_Notebook.ipynb'
total = prefix + mystr + suffix
print total
try :
    if(__IPYTHON__) :
        get_ipython().system(total)
except NameError :
    pass
um8ra
  • 185
  • 2
  • 12
0

For anyone trying to do the same thing look into the papermill library. It can run a notebook and change its parameters on the fly.

import papermill as pm
notebook_to_execute = 'index.ipynb'
notebook_filename = 'test.ipynb' # This file will be created by papermill
pm.execute_notebook(notebook_to_execute,
                    notebook_filename,
                    parameters={'your_variable':'test1', 
                                'your_second_variable':f'test2'})