#!/usr/bin/env python
import sys
import json


def _keep(cell):
    is_code = cell['cell_type'] == 'code'
    return is_code


def write_to_file(fpath_in, fpath_out):
    with open(fpath_in, 'r') as f:
        notebook = json.load(f)
    cells = filter(_keep, notebook['cells'])
    with open(fpath_out, 'w') as f:
        for cell in cells:
            source = ''.join(cell['source']) + 3 * '\n'
            f.write(source)


def main():
    f1, f2 = sys.argv[1:3]
    write_to_file(f1, f2)


if __name__ == '__main__':
    main()

#!/usr/bin/env python
import sys
import json


def _keep(cell):
    is_code = cell['cell_type'] == 'code'
    return is_code


def write_to_file(fpath_in, fpath_out):
    with open(fpath_in, 'r') as f:
        notebook = json.load(f)
    cells = filter(_keep, notebook['cells'])
    with open(fpath_out, 'w') as f:
        for cell in cells:
            source = ''.join(cell['source']) + 3 * '\n'
            f.write(source)


def main():
    f1, f2 = sys.argv[1:3]
    write_to_file(f1, f2)


if __name__ == '__main__':
    main()

#!/usr/bin/env python