本文整理汇总了Python中nbconvert.HTMLExporter.from_notebook_node方法的典型用法代码示例。如果您正苦于以下问题:Python HTMLExporter.from_notebook_node方法的具体用法?Python HTMLExporter.from_notebook_node怎么用?Python HTMLExporter.from_notebook_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nbconvert.HTMLExporter
的用法示例。
在下文中一共展示了HTMLExporter.from_notebook_node方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_jupyter
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def update_jupyter(self, s, keywords):
'''Update @jupyter node in the vr pane.'''
pc = self
c = pc.c
if pc.must_change_widget(QtWebKitWidgets.QWebView):
# g.trace('===== instantiating QWebView')
w = QtWebKitWidgets.QWebView()
n = c.config.getInt('qweb_view_font_size')
if n:
settings = w.settings()
settings.setFontSize(settings.DefaultFontSize, n)
pc.embed_widget(w)
assert(w == pc.w)
else:
w = pc.w
url = g.getUrlFromNode(c.p)
if url and nbformat:
s = urlopen(url).read().decode()
try:
nb = nbformat.reads(s, as_version=4)
e = HTMLExporter()
(s, junk_resources) = e.from_notebook_node(nb)
except nbformat.reader.NotJSONError:
# Assume the result is html.
pass
elif url:
s = 'can not import nbformt: %r' % url
else:
s = g.u('')
if isQt5:
w.hide() # This forces a proper update.
w.setHtml(s)
w.show()
c.bodyWantsFocusNow()
示例2: bundle_notebook
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def bundle_notebook(vid, fileid):
"""Return a file from the bundle"""
from ambry.orm.file import File
import nbformat
from traitlets.config import Config
from nbconvert import HTMLExporter
b = aac.library.bundle(vid)
nbfile = b.build_source_files.file_by_id(fileid)
notebook = nbformat.reads(nbfile.unpacked_contents, as_version=4)
html_exporter = HTMLExporter()
html_exporter.template_file = 'basic'
(body, resources) = html_exporter.from_notebook_node(notebook)
cxt = dict(
vid=vid,
b=b,
fileid=fileid,
nbfile=nbfile,
notebooks=b.build_source_files.list_records(File.BSFILE.NOTEBOOK),
notebook=notebook,
notebook_html=body,
**aac.cc
)
return aac.render('bundle/notebook.html', **cxt)
示例3: execute
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def execute(self):
print("Cleaning lowfat/reports/html ...")
old_reports = os.listdir("lowfat/reports/html")
for old_report in old_reports:
print("- Removing lowfat/reports/html/{}".format(old_report))
os.remove("lowfat/reports/html/{}".format(old_report))
print("Cleaning of lowfat/reports/html is complete.")
notebook_filenames = os.listdir("lowfat/reports")
for notebook_filename in notebook_filenames:
if not notebook_filename.endswith(".ipynb"):
continue
print("Processing lowfat/reports/{}".format(notebook_filename))
# Based on Executing notebooks, nbconvert Documentation by Jupyter Development Team.
# https://nbconvert.readthedocs.io/en/latest/execute_api.html
with open("lowfat/reports/{}".format(notebook_filename)) as file_:
notebook = nbformat.read(file_, as_version=4)
# Kernel is provided by https://github.com/django-extensions/django-extensions/
execute_preprocessor = ExecutePreprocessor(timeout=600, kernel_name='django_extensions')
execute_preprocessor.preprocess(notebook, {'metadata': {'path': '.'}})
html_exporter = HTMLExporter()
html_exporter.template_file = 'basic'
(body, dummy_resources) = html_exporter.from_notebook_node(notebook)
with open('lowfat/reports/html/{}.html'.format(notebook_filename), 'wt') as file_:
file_.write(body)
示例4: nb_to_html
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def nb_to_html(root, template='basic', version=4, timeout=600, kernel='python3'):
'''
This functions executes a Jupyter notebook and creates the related
HTML file.
Args:
root (str): name of the file without the .ipynb extension
template (str): name of the template (to be in the current folder as template.tpl)
version (int): version of the notebook
timeout (float): maximum time spent per cell
kernel (str)
Returns:
None
The function executes root.ipynb into root_exe.ipynb and creates the file root.html.
'''
with open(root + '.ipynb') as f:
nb = nbformat.read(f, as_version=version)
ep = ExecutePreprocessor(timeout=timeout, kernel_name=kernel)
ep.preprocess(nb, {'metadata': {'path': '.'}})
with open(root + '_exe.ipynb', 'wt') as f:
nbformat.write(nb, f)
html_exporter = HTMLExporter()
html_exporter.template_file = template
with open(root + '_exe.ipynb', mode='r') as f:
notebook = nbformat.reads(''.join(f.readlines()), as_version=version)
(body, _) = html_exporter.from_notebook_node(notebook)
codecs.open(root + '.html', 'w', encoding='utf-8').write(body)
示例5: NarrativeExporter
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
class NarrativeExporter():
def __init__(self):
c = Config()
c.HTMLExporter.preprocessors = [NarrativePreprocessor]
c.TemplateExporter.template_path = ['.', self._narrative_template_path()]
c.CSSHTMLHeaderPreprocessor.enabled = True
self.html_exporter = HTMLExporter(config=c)
self.html_exporter.template_file = 'narrative'
self.ws_client = Workspace(URLS.workspace)
self.narr_fetcher = NarrativeIO()
def _narrative_template_path(self):
return os.path.join(os.environ.get('NARRATIVE_DIR', '.'), 'src', 'biokbase', 'narrative', 'exporter', 'templates')
def export_narrative(self, narrative_ref, output_file):
nar = self.narr_fetcher.read_narrative(narrative_ref)
nar = nar['data']
# # 1. Get the narrative object
# # (put in try/except)
# # (should also raise an error if narrative is not public)
# nar = self.ws_client.get_objects([{'ref': narrative_ref}])
# # put in separate try/except
# nar = nar[0]['data']
# 2. Convert to a notebook object
kb_notebook = nbformat.reads(json.dumps(nar), as_version=4)
# 3. make the thing
(body, resources) = self.html_exporter.from_notebook_node(kb_notebook)
with open(output_file, 'w') as output_html:
output_html.write(body)
示例6: export_notebook_to_html
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def export_notebook_to_html(notebook_fp, output_dir):
nb = read_in_notebook(notebook_fp)
html_exporter = HTMLExporter()
body, resources = html_exporter.from_notebook_node(nb)
_, notebook_name, _ = get_file_name_pieces(notebook_fp)
out_fp = make_file_path(output_dir, notebook_name, ".html")
with open(out_fp, "w", encoding="utf8") as f:
f.write(body)
示例7: export_notebook_to_html
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def export_notebook_to_html(notebook, datestamp, mark_as_latest=True):
html_exporter = HTMLExporter()
html, _resources = html_exporter.from_notebook_node(notebook)
output_path = get_monitoring_notebook_output_path(datestamp, ext='html')
with open(output_path, 'wt') as outfile:
outfile.write(html)
if mark_as_latest:
latest_notebook_path = get_monitoring_notebook_output_path('latest', ext='html')
copyfile(output_path, latest_notebook_path)
示例8: output_HTML
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def output_HTML(read_file, output_file):
from nbconvert import HTMLExporter
import codecs
import nbformat
exporter = HTMLExporter()
# read_file is '.ipynb', output_file is '.html'
output_notebook = nbformat.read(read_file, as_version=4)
output, resources = exporter.from_notebook_node(output_notebook)
codecs.open(output_file, 'w', encoding='utf-8').write(output)
示例9: write_html
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def write_html(self):
print("writing", self.html)
html_exporter = HTMLExporter()
html_exporter.template_file = 'full'
# do a deeo copy to any chance of overwriting the original notebooks
content = copy.deepcopy(self.content)
content.cells = content.cells[2:-1]
content.cells[0].source = "# " + self.numbered_title
(body, resources) = html_exporter.from_notebook_node(content)
with open(self.html, 'w') as f:
f.write(body)
示例10: convert_nb_html
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def convert_nb_html(nb):
"""
Convert a notebooks output to HTML
"""
nb = run_notebook(nb)
config = Config({'HTMLExporter': {'default_template': 'basic'}})
exportHtml = HTMLExporter(config=config)
html, resources = exportHtml.from_notebook_node(nb)
soup = BeautifulSoup(html)
filters = ["output", "text_cell_render border-box-sizing rendered_html"]
return ''.join(map(str, soup.findAll("div", {"class": filters})))
示例11: preview
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def preview(self, filepath):
"""
Preview a notebook store in the Storage
:param filepath: Path to the notebook to preview on Storage
:return a notebook in html format
"""
self.log.debug("Make a Html preview of notebook '%s'" % filepath);
nb = self.read(filepath);
html_conveter = HTMLExporter()
(body, resources) = html_conveter.from_notebook_node(nb)
return body;
示例12: render
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def render(file):
"""Generate the result HTML."""
fp = file.open()
content = fp.read()
fp.close()
notebook = nbformat.reads(content.decode('utf-8'), as_version=4)
html_exporter = HTMLExporter()
html_exporter.template_file = 'basic'
(body, resources) = html_exporter.from_notebook_node(notebook)
return body, resources
示例13: _nbconvert_to_html
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def _nbconvert_to_html(cls, doc):
'''Use nbconvert to render a notebook as HTML.
Strip the headings from the first markdown cell to avoid showing the
page title twice on the blog.
'''
if doc.cells and doc.cells[0].cell_type == 'markdown':
source = doc.cells[0].source
doc.cells[0].source = re.sub('^# .*\n', '', source)
e = HTMLExporter()
e.template_file = 'basic'
return e.from_notebook_node(doc)[0]
示例14: as_html
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def as_html(self, file):
with File().open(file) as fp:
notebook = nbformat.reads(fp.read().decode(), as_version=4)
exporter = HTMLExporter()
#exporter.template_file = 'basic'
(body, resources) = exporter.from_notebook_node(notebook)
def stream():
cherrypy.response.headers['Content-Type'] = 'text/html'
yield body
return stream
示例15: post
# 需要导入模块: from nbconvert import HTMLExporter [as 别名]
# 或者: from nbconvert.HTMLExporter import from_notebook_node [as 别名]
def post(self):
id=self.get_argument("path")
print id
db=create_engine('postgresql://postgres:[email protected]/ishtar')
fileContent=reads_base64(pgquery.get_file(db, "share", id, include_content=True)['content'])
#notebook= nbformat.reads(fileContent, as_version=4)
notebook=fileContent
db.dispose()
html_exporter = HTMLExporter()
html_exporter.template_file = 'basic'
(body, resources) = html_exporter.from_notebook_node(notebook)
self.write(body)