def write_notebook(self, include_html=True): suffix = "_responses_with_names" if self.include_usernames else "_responses" nb_name = self.nb_name_stem + suffix output_file = os.path.join(PROCESSED_NOTEBOOK_DIR, nb_name + '.ipynb') html_output = os.path.join(PROCESSED_NOTEBOOK_DIR, nb_name + '.html') remove_duplicate_answers = not self.include_usernames filtered_cells = [] for prompt in self.question_prompts: filtered_cells += prompt.cells answers = prompt.answers_without_duplicates if remove_duplicate_answers else prompt.answers for gh_username, response_cells in answers.items(): if self.include_usernames: filtered_cells.append( NotebookUtils.markdown_heading_cell( self.gh_username_to_fullname(gh_username), 4)) filtered_cells.extend(response_cells) answer_book = deepcopy(self.template) answer_book['cells'] = filtered_cells nb = nbformat.from_dict(answer_book) print "Writing", output_file with io.open(output_file, 'wt') as fp: nbformat.write(nb, fp, version=4) if include_html: # TODO why is the following necessary? nb = nbformat.reads(nbformat.writes(nb, version=4), as_version=4) html_content, _ = nbconvert.export_html(nb) print "Writing", html_output with io.open(html_output, 'w') as fp: fp.write(html_content)
def write_notebook(self, include_html=True): suffix = "_responses_with_names" if self.include_usernames else "_responses" nb_name = self.nb_name_stem + suffix output_file = os.path.join(PROCESSED_NOTEBOOK_DIR, nb_name + '.ipynb') html_output = os.path.join(PROCESSED_NOTEBOOK_DIR, nb_name + '.html') remove_duplicate_answers = not self.include_usernames filtered_cells = [] for prompt in self.question_prompts: filtered_cells += prompt.cells answers = prompt.answers_without_duplicates if remove_duplicate_answers else prompt.answers for gh_username, response_cells in answers.items(): if self.include_usernames: filtered_cells.append( NotebookUtils.markdown_heading_cell(self.gh_username_to_fullname(gh_username), 4)) filtered_cells.extend(response_cells) answer_book = deepcopy(self.template) answer_book['cells'] = filtered_cells nb = nbformat.from_dict(answer_book) print "Writing", output_file with io.open(output_file, 'wt') as fp: nbformat.write(nb, fp, version=4) if include_html: # TODO why is the following necessary? nb = nbformat.reads(nbformat.writes(nb, version=4), as_version=4) html_content, _ = nbconvert.export_html(nb) print "Writing", html_output with io.open(html_output, 'w') as fp: fp.write(html_content)
def processed_notebook(assignment_id): with open('processed_notebooks/%s_reading_journal_responses.ipynb' % assignment_id) as f: nb = nbformat.reads(f.read(), as_version=4) str, _ = nbconvert.export_html(nb) assignment_name = assignments[assignment_id][1] return flask.render_template( 'processed_notebook.html', course_name=COURSE_NAME, title=' '.join([assignment_name, 'Processed Notebook']), nb_html=str)
def _rich_help(*args): with warnings.catch_warnings(): # ignore warnings about pandoc, nodejs, etc. warnings.filterwarnings('ignore', message='Node.js') output, resources = export_html(_rich_help.__richdoc__, config=Config({ 'CSSHTMLHeaderPreprocessor' : { 'enabled' : False }, 'HTMLExporter' : { 'template_file' : 'basic' } })) # include style in every output; tried it global on import, but if the import is # re-run it's lost because there is no output on a repeat module import output = '''<style> .output .input_prompt, .output .output .output_prompt, .output .output .prompt { display: none; } .output .input_area pre { padding: 0.4em; } </style> ''' + output display(HTML(output))
def _rich_help(*args): with warnings.catch_warnings(): # ignore warnings about pandoc, nodejs, etc. warnings.filterwarnings('ignore', message='Node.js') output, resources = export_html(_rich_help.__richdoc__, config=Config({ 'CSSHTMLHeaderPreprocessor': { 'enabled': False }, 'HTMLExporter': { 'template_file': 'basic' } })) # include style in every output; tried it global on import, but if the import is # re-run it's lost because there is no output on a repeat module import output = '''<style> .output .input_prompt, .output .output .output_prompt, .output .output .prompt { display: none; } .output .input_area pre { padding: 0.4em; } </style> ''' + output display(HTML(output))
else: raise Exception(err_msg.format('password')) if args.template: tpl = args.template if tpl in ['basicx']: pathtpl, _ = os.path.split(os.path.abspath(__file__)) pathtpl = os.path.join(pathtpl, 'templates', "{}.tpl".format(tpl)) post = """<style>{}</style>\n""".format(CSS_CODE) else: pathtpl = "basic" post = "" if args.nb: post += nbc.export_html(nb = args.nb, template_file = pathtpl, config = c)[0] else: raise Exception(err_msg.format('nb')) if args.title: title = args.title else: raise Exception(err_msg.format('title')) if args.categories: categories = args.categories else: categories = ['Uncategorized'] if args.tags: