'Export and convert IPython notebooks.
This function can export the current IPython history to a notebook file.
For example, to export the history to "foo.ipynb" do "%notebook foo.ipynb".
The -e or --export flag is deprecated in IPython 5.2, and will be
removed in the future.'

@magic_arguments.magic_arguments()
@magic_arguments.argument('-e', '--export', action='store_true', default=False, help=argparse.SUPPRESS)
@magic_arguments.argument('filename', type=str, help='Notebook    name    or    filename')
@line_magic
def notebook(self, s):

    args = magic_arguments.parse_argstring(self.notebook, s)
    from nbformat import write, v4
    cells = []
    hist = list(self.shell.history_manager.get_range())
    if (len(hist) <= 1):
        raise ValueError('History    is    empty,    cannot    export')
    for (session, execution_count, source) in hist[:(-1)]:
        cells.append(v4.new_code_cell(execution_count=execution_count, source=source))
    nb = v4.new_notebook(cells=cells)
    with io.open(args.filename, 'w', encoding='utf-8') as f:
        write(nb, f, version=4)
