Beispiel #1
0
def convert_folder(arg):
    # first, we need to somehow reconstruct the hierarchy of the input folder
    # to the output folder
    # the way we do that by get the input path, and then subtract it from the
    # actual notes path.
    tot_base_part = len(Path(arg['input_file']).parts)
    for note in glob.iglob(os.path.join(arg['input_file'], '**/*.ipynb'),
                           recursive=True):
        logger.debug("Processing {}".format(note))
        # $note is also a path, but joined with the $input_file
        # get note but with strip base, only preserve the hierarchy
        # remeber: -1 since we do not want to include the file, only the
        # folder hierarchy
        note_path_hierarchy = os.path.join(*Path(note).parts[tot_base_part:-1])
        note_fname = os.path.split(note)[-1]
        note_name, note_ext = os.path.splitext(note_fname)

        note_output = os.path.join(arg['output_file'], note_path_hierarchy,
                                   note_name + ".md")
        note_media_output = os.path.join(arg['media_folder'],
                                         note_path_hierarchy, note_name)

        logger.debug("Converting")
        nb = Notebook(note)
        nb.export(note_output, img_to=note_media_output)
Beispiel #2
0
def convert_file(arg):
    nb = Notebook(arg['input_file'])
    nb.export(arg['output_file'], img_to=arg['media_folder'])