Here is what I wrote:
using JSON
get_code_cells(j::Dict) = filter(x->x["cell_type"] == "code", j["cells"])
function parse_code_cell(c::Dict)
buf = IOBuffer()
write(buf, "begin\n")
map(x->write(buf, x), c["source"])
write(buf, "\nend")
src = bytestring(buf)
parse(src)
end
extract_code(cells::Vector) = Expr[parse_code_cell(c) for c in cells]
extract_code(j::Dict) = extract_code(get_code_cells(j))
eval_code(j::Dict) = map(eval, extract_code(j))
const fn = ARGS[1]
eval_code(JSON.parsefile(fn))
This seems to work for many laptops, but not for everyone. In particular, he could not start the laptop, where I had
using PyCall
@pyimport seaborn as sns
eval , @pyimport, ( PyCall).
, , .
- ...
ipython nbconvert, , include , . ( , ). / .
const fn = abspath(ARGS[1])
dir = dirname(fn)
src = readall(`ipython nbconvert --to script --stdout $fn`)
script_fn = joinpath(dir, string(randstring(30), ".jl"))
open(script_fn, "w") do f
write(f, src)
end
try
include(script_fn)
catch
warn("Failed executing script from file")
end
rm(script_fn)