2017-01-18 21:23:06 +01:00
|
|
|
import os, sys, io
|
|
|
|
|
2017-01-14 22:15:24 +01:00
|
|
|
print(sys.argv[1])
|
|
|
|
infile = open(sys.argv[1], encoding="utf8")
|
|
|
|
data = infile.read()
|
|
|
|
infile.close()
|
|
|
|
outfile = open(sys.argv[1], "w", encoding="utf8")
|
|
|
|
|
2017-01-18 21:23:06 +01:00
|
|
|
buf = io.StringIO(data)
|
|
|
|
first_inline = False
|
|
|
|
is_code_cell = False
|
|
|
|
for line in buf:
|
|
|
|
# can't comment out first inline that is always in the first cell
|
|
|
|
if '"cell_type":' in line:
|
|
|
|
is_code_cell = '"code"' in line
|
|
|
|
|
|
|
|
if is_code_cell:
|
|
|
|
if '%matplotlib inline' in line:
|
|
|
|
if first_inline:
|
|
|
|
line = line.replace("%matplotlib inline", "#%matplotlib inline")
|
|
|
|
first_inline = True
|
|
|
|
|
|
|
|
line = line.replace("%matplotlib notebook", "#%matplotlib notebook")
|
|
|
|
line = line.replace("time.sleep", "#time.sleep")
|
|
|
|
line = line.replace("fig.canvas.draw", "#fig.canvas.draw")
|
|
|
|
line = line.replace("plt.gcf().canvas.draw", "#plt.gcf().canvas.draw")
|
|
|
|
outfile.write(line)
|
2017-01-14 22:15:24 +01:00
|
|
|
|
|
|
|
outfile.close()
|