예제 #1
0
파일: ein.py 프로젝트: ki-chi/dotfiles
def export_nb(nb_json, format):
    import IPython.nbconvert as nbconvert
    import IPython.nbformat as nbformat

    nb = nbformat.reads(nb_json, nbformat.NO_CONVERT)
    output = nbconvert.export_by_name(format, nb)
    print(output[0])
예제 #2
0
파일: export.py 프로젝트: lisabang/iqsar
    def __init__(self,name, nb):
        js = """IPython.notebook.kernel.widget_manager.get_model('%s').then(function(model) {
    model.set('value', IPython.notebook.notebook_name);
    model.save();
});
""" % notebook_name.model_id
        display(Javascript(data=js))
        filename = notebook_name.value
        exporter_names = widgets.Dropdown(options=get_export_names(), value='html')
        export_button = widgets.Button(description="Export")
        download_link = widgets.HTML(visible=False)
    # Get a unique key for the notebook and set it in the resources object.
        notebook_name = name[:name.rfind('.')]
        resources = {}
        resources['unique_key'] = notebook_name
        resources['output_files_dir'] = '%s_files' % notebook_name

    # Try to export

# Get the current notebook's name by pushing JavaScript to the browser that sets the notebook name in a string widget.


# Export the notebook when the export button is clicked.
#file_writer = FilesWriter()

        try:
            output, resources = export_by_name(exporter_names.value, nb)
        except ConversionException as e:
            download_link.value = "<br>Could not export notebook!"
        else:
            write_results = file_writer.write(output, resources, notebook_name=notebook_name)
    
            download_link.value = "<br>Results: <a href='files/{filename}'><i>\"{filename}\"</i></a>".format(filename=write_results)
            download_link.visible = True
예제 #3
0
파일: export2.py 프로젝트: lisabang/iqsar
     def export8(self,name, nb):
         notebook_name = name[:name.rfind('.')]
         resources = {}
         resources['unique_key'] = notebook_name
         resources['output_files_dir'] = '%s_files' % notebook_name
         try:
             output, resources = export_by_name(exporter_names.value, nb)
         except ConversionException as e:
             download_link.value = "<br>Could not export notebook!"
         else:
             write_results = file_writer.write(output, resources, notebook_name=notebook_name)
 
             download_link.value = "<br>Results: <a href='files/{filename}'><i>\"{filename}\"</i></a>".format(filename=write_results)
             download_link.visible = True
예제 #4
0
def export_nb(nb_json, format):
    import IPython.nbconvert as nbconvert
    import IPython.nbformat as nbformat
    nb = nbformat.reads(nb_json, nbformat.NO_CONVERT)
    output = nbconvert.export_by_name(format, nb)
    print(output[0])
예제 #5
0
def export_nb(nb_filename, format):
    import IPython.nbconvert as nbconvert
    with open(nb_filename, 'r') as f:
        output = nbconvert.export_by_name(format, nb_filename)
    print(output[0])