Skip to content

Commit

Permalink
WIP: updating featured recipes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rossant committed Feb 27, 2015
1 parent 4785c99 commit 717155a
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions tools/convert_nbformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ def iter_chapters(root):
if _.startswith('chapter')]):
yield chapter

def iter_recipes(root, dir):
def iter_recipes(root, dir=''):
files = sorted([_ for _ in os.listdir(op.join(root, dir))
if re.match(r'\d{2}\_[^.]+\.ipynb', _)])
for file in files:
yield file

curdir = op.realpath(op.dirname(os.path.abspath(__file__)))
root = op.realpath(op.join(curdir, '../notebooks'))


def fix_v3(path):
with open(path, 'r') as f:
nb = json.load(f)
Expand All @@ -50,8 +46,6 @@ def fix_v3(path):
with open(path, 'w') as f:
json.dump(nb, f, indent=2)



def convert_to_v4(path):
nb = read(path, 3)
nb_new = convert(nb, 4)
Expand Down Expand Up @@ -79,17 +73,35 @@ def convert_to_v4(path):
validate(nb_new)
write(nb_new, path)

curdir = op.realpath(op.dirname(os.path.abspath(__file__)))
root = op.realpath(op.join(curdir, '../notebooks'))
featured = op.realpath(op.join(curdir, '../featured'))

if __name__ == '__main__':

for chapter in iter_chapters(root):
for recipe in iter_recipes(root, chapter):
file = op.join(root, chapter, recipe)
# Chapter notebooks
# for chapter in iter_chapters(root):
# for recipe in iter_recipes(root, chapter):
# file = op.join(root, chapter, recipe)

# if recipe in ('01_notebook.ipynb',
# '02_pandas.ipynb',
# '03_numpy.ipynb',):
# continue
# print("converting", file)

# # fix_v3(file)
# convert_to_v4(file)

# Featured notebooks
for recipe in iter_recipes(featured):
file = op.join(featured, recipe)

if recipe in ('01_notebook.ipynb',
'02_pandas.ipynb',
'03_numpy.ipynb',):
continue
print("converting", file)
if recipe in ('01_notebook.ipynb',
'02_pandas.ipynb',
'03_numpy.ipynb',):
continue
print("converting", file)

# fix_v3(file)
convert_to_v4(file)
# fix_v3(file)
convert_to_v4(file)

0 comments on commit 717155a

Please sign in to comment.