@@ -29,16 +29,12 @@ def iter_chapters(root):
2929 if _ .startswith ('chapter' )]):
3030 yield chapter
3131
32- def iter_recipes (root , dir ):
32+ def iter_recipes (root , dir = '' ):
3333 files = sorted ([_ for _ in os .listdir (op .join (root , dir ))
3434 if re .match (r'\d{2}\_[^.]+\.ipynb' , _ )])
3535 for file in files :
3636 yield file
3737
38- curdir = op .realpath (op .dirname (os .path .abspath (__file__ )))
39- root = op .realpath (op .join (curdir , '../notebooks' ))
40-
41-
4238def fix_v3 (path ):
4339 with open (path , 'r' ) as f :
4440 nb = json .load (f )
@@ -50,8 +46,6 @@ def fix_v3(path):
5046 with open (path , 'w' ) as f :
5147 json .dump (nb , f , indent = 2 )
5248
53-
54-
5549def convert_to_v4 (path ):
5650 nb = read (path , 3 )
5751 nb_new = convert (nb , 4 )
@@ -79,17 +73,35 @@ def convert_to_v4(path):
7973 validate (nb_new )
8074 write (nb_new , path )
8175
76+ curdir = op .realpath (op .dirname (os .path .abspath (__file__ )))
77+ root = op .realpath (op .join (curdir , '../notebooks' ))
78+ featured = op .realpath (op .join (curdir , '../featured' ))
79+
8280if __name__ == '__main__' :
8381
84- for chapter in iter_chapters (root ):
85- for recipe in iter_recipes (root , chapter ):
86- file = op .join (root , chapter , recipe )
82+ # Chapter notebooks
83+ # for chapter in iter_chapters(root):
84+ # for recipe in iter_recipes(root, chapter):
85+ # file = op.join(root, chapter, recipe)
86+
87+ # if recipe in ('01_notebook.ipynb',
88+ # '02_pandas.ipynb',
89+ # '03_numpy.ipynb',):
90+ # continue
91+ # print("converting", file)
92+
93+ # # fix_v3(file)
94+ # convert_to_v4(file)
95+
96+ # Featured notebooks
97+ for recipe in iter_recipes (featured ):
98+ file = op .join (featured , recipe )
8799
88- if recipe in ('01_notebook.ipynb' ,
89- '02_pandas.ipynb' ,
90- '03_numpy.ipynb' ,):
91- continue
92- print ("converting" , file )
100+ if recipe in ('01_notebook.ipynb' ,
101+ '02_pandas.ipynb' ,
102+ '03_numpy.ipynb' ,):
103+ continue
104+ print ("converting" , file )
93105
94- # fix_v3(file)
95- convert_to_v4 (file )
106+ # fix_v3(file)
107+ convert_to_v4 (file )
0 commit comments