Octoframes / jupyter_capture_output

A cellmagic that captures celloutput such as text, image or video to files.
https://octoframes.github.io/jupyter_capture_output/
MIT License
31 stars 0 forks source link

capture_auto #11

Open kolibril13 opened 1 year ago

kolibril13 commented 1 year ago

Automatically detects the format of the output. Two options here:

  1. the capture output format is determined by the file name ending, e.g. %%capture_auto--path "foo.txt" will detect it is txt.
  2. the capture output format is determined by the cell output, e.g. %%capture_auto--path "foo" will save the output to foo.mp4 if the output is of type video, or to foo.png if the output type is an image.

Another thought: Option 2 could be extended in the following way: if there are multiple outputs, they can be all saved in respective files, e.g. foo.txt , foo.mp4 and foo.png.

Here is an implementation start point:


    @magic_arguments.magic_arguments()  ################### Auto
    @magic_arguments.argument(
        "--path",
        "-p",
        default=None,
        help=(
            "Auto detect what to capture based on file ending"
        ),
    )
    @cell_magic
    def capture_auto(self, line, cell):
        args = magic_arguments.parse_argstring(CaptureMagic.capture_auto, line)
        path_str = args.path.strip('"')
        p_pathlib = path_preprocessing(path_str)
        if p_pathlib.suffix == ".png":
            pass
        if p_pathlib.suffix == ".mp4":
            pass
        if p_pathlib.suffix == ".txt":
            pass
        if p_pathlib.suffix == ".py":
            pass