Small script to flatten an IPython notebook (much like https://gist.github.com/takluyver/bc8f3275c7d34abb68bf), using jq instead of python. It is significantly faster. Put it somewhere in your path and make it executable. You can call it with nbflatten.jq --arg show_output 0
to suppress showing outputs (by default they are shown).
Last active
December 20, 2017 13:26
-
-
Save jfeist/cd00aa3b681092e1d5dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
jq -r 'def banner: "\(.) " + (28-(.|length))*"-"; | |
("Non-cell info" | banner), del(.cells), "", | |
(.cells[] | ("\(.cell_type) cell" | banner), | |
"\(.source|add)", | |
if ($show_output == "1") then | |
"", | |
( select(.cell_type=="code" and (.outputs|length)>0) | | |
("output" | banner), | |
(.outputs[] | | |
(select(.text) | "\(.text|add)" | rtrimstr("\n")), | |
(select(.traceback) | (.traceback|join("\n"))), | |
(select(.text or .traceback|not) | "(Non-plaintext output)") | |
), | |
"" | |
) | |
else "" | |
end | |
)' "$@" --arg show_output 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is amazing, thank you!