#!/usr/bin/env python # coding: utf-8 # In[7]: # copy tree structure import os try: os.mkdir(os.path.join('./html')) except OSError: pass try: os.mkdir(os.path.join('./html/LABS')) except OSError: pass ld = os.listdir('.') chapters = [n for n in os.listdir('.') if '00'<= n <='99'] for c in chapters: try: os.mkdir(os.path.join('./html',c)) except OSError: pass labs = [n for n in os.listdir('./LABS/') if '00'<= n <='99'] for c in labs: try: os.mkdir(os.path.join('./html/LABS',c)) except OSError: pass # In[9]: # export all .ipynb to html def replace_ipynb_by_html(fname): s = open(fname).read() r = s.replace('.ipynb','.html') fid = open(fname,'wt') fid.write(r) fid.close() def convert(chapters,path_source='.',path_dest='./html'): for c in chapters: source = os.path.join(path_source,c) destination = os.path.join(path_dest,c) names = [os.path.splitext(fn)[0] for fn in os.listdir(source) if fn.endswith('.ipynb')] for n in names: nb_filename = os.path.join(source,n+'.ipynb') html_filename = os.path.join(destination,n+'.html') print nb_filename, html_filename # convert notebook s = get_ipython().getoutput("ipython nbconvert --to html --output '$html_filename' '$nb_filename'") replace_ipynb_by_html(html_filename) convert(chapters) convert(labs,'./LABS','./html/LABS') # In[10]: # convert indexes nb_filename = os.path.join('.','Index.ipynb') html_filename = os.path.join('./html','Index.html') s = get_ipython().getoutput("ipython nbconvert --to html --output '$html_filename' '$nb_filename'") replace_ipynb_by_html(html_filename) nb_filename = os.path.join('.','Index-labs1-6.ipynb') html_filename = os.path.join('./html','Index-labs1-6.html') s = get_ipython().getoutput("ipython nbconvert --to html --output '$html_filename' '$nb_filename'") replace_ipynb_by_html(html_filename) # In[ ]: