def main(): path_handler = common.PathHandler('trim') for arg in path_handler.args: file_ipynb = path_handler.get_file(arg, '.ipynb') nb_json = ds.load_json(file_ipynb) cells = path_handler.load_config(arg)['cells'] nb_json_cells = nb_json['worksheets'][0]['cells'] nb_json['worksheets'][0]['cells'] = nb_json_cells[cells[0]:cells[1]] file_tmp_ipynb = file_ipynb.replace('.ipynb', '.tmp.ipynb') ds.dump_json(nb_json, file_tmp_ipynb, indent=1)
def main(): path_handler = common.PathHandler('publish') path_image = path_handler.GLOBALS['STREAMBED']['image'] for arg in path_handler.args: dir_nb = path_handler.get_path(arg) file_html = path_handler.get_file(arg, '.tmp.html') config = path_handler.load_config(arg) tree = path_handler.get_tree(arg) body = ds.load_soup(file_html).body # Download images wget_images(body, arg, config['title_short'], dir_nb, path_image, tree['static']['image']) # Update body remove_h1(body) update_anchors(body) add_lightbox(body) add_in_out_anchors(body) # Dump body ds.dump_soup(body, tree['includes']['nb']['body'], remove_tag='body') # Append and dump config config = append_config(config, arg, path_handler) ds.dump_json(config, tree['includes']['nb']['config']) # Append and dump references references = path_handler.load_references() references = append_references(references, path_handler) ds.dump_json(references, tree['includes']['references']) # Make url, sitemaps and redirect files nbs = path_handler.nbs relative_urls = path_handler.get_relative_urls() dfy.make_urls(nbs, relative_urls, tree['urls'], app_name='api_docs', class_name='IPythonNotebookPage') dfy.make_sitemaps(nbs, relative_urls, tree['sitemaps'])
def main(): path_handler = common.PathHandler('trim') for arg in path_handler.args: file_ipynb = path_handler.get_file(arg, '.ipynb') nb_json = ds.load_json(file_ipynb) cells = path_handler.load_config(arg)['cells'] if nb_json['nbformat'] == 4: nb_json_cells = nb_json['cells'] nb_json['cells'] = get_slice(nb_json_cells, cells) else: nb_json_cells = nb_json['worksheets'][0]['cells'] nb_json['worksheets'][0]['cells'] = get_slice(nb_json_cells, cells) file_tmp_ipynb = file_ipynb.replace('.ipynb', '.tmp.ipynb') ds.dump_json(nb_json, file_tmp_ipynb, indent=1)