def extract_zip(zip_name, exclude_term=None): """Extracts a zip file to its containing directory.""" zip_dir = os.path.dirname(os.path.abspath(zip_name)) try: with zipfile.ZipFile(zip_name) as z: # write each zipped file out if it isn't a directory files = [zip_file for zip_file in z.namelist() if not zip_file.endswith("/")] print("Extracting %i files from %r." % (len(files), zip_name)) for zip_file in files: # remove any provided extra directory term from zip file if exclude_term: dest_file = zip_file.replace(exclude_term, "") else: dest_file = zip_file dest_file = os.path.normpath(os.path.join(zip_dir, dest_file)) dest_dir = os.path.dirname(dest_file) # make directory if it does not exist if not os.path.isdir(dest_dir): os.makedirs(dest_dir) # read file from zip, then write to new directory data = z.read(zip_file) with open(dest_file, "wb") as f: f.write(encode_utf8(data)) except zipfile.error as e: print("Bad zipfile (%r): %s" % (zip_name, e)) raise e
def polynomial(): """ Very simple embedding of a polynomial chart""" # Grab the inputs arguments from the URL # This is automated by the button args = flask.request.args # Get all the form arguments in the url with defaults color = colors[getitem(args, 'color', 'Black')] _from = int(getitem(args, '_from', 0)) to = int(getitem(args, 'to', 10)) # Create a polynomial line graph x = list(range(_from, to + 1)) fig = figure(title="Polynomial") fig.line(x, [i ** 2 for i in x], color=color, line_width=2) # Configure resources to include BokehJS inline in the document. # For more details see: # http://bokeh.pydata.org/en/latest/docs/reference/resources_embedding.html#module-bokeh.resources plot_resources = RESOURCES.render( js_raw=INLINE.js_raw, css_raw=INLINE.css_raw, js_files=INLINE.js_files, css_files=INLINE.css_files, ) # For more details see: # http://bokeh.pydata.org/en/latest/docs/user_guide/embedding.html#components script, div = components(fig, INLINE) html = flask.render_template( 'embed.html', plot_script=script, plot_div=div, plot_resources=plot_resources, color=color, _from=_from, to=to ) return encode_utf8(html)
def get(self, key): _data = shelve.open('bokeh.server') key = encode_utf8(key) data = _data.get(key, None) if data is None: return None attrs = json.loads(decode_utf8(data)) _data.close() return attrs
def main(ipynb): print("running %s" % ipynb) with io.open(ipynb, encoding='utf8') as f: nb = read(f, NO_CONVERT) test_notebook(nb) base, ext = os.path.splitext(ipynb) exportHtml = HTMLExporter() (body, resources) = exportHtml.from_notebook_node(nb) outfile = ipynb + ".html" open(outfile, 'w').write(encode_utf8(body)) print("wrote %s" % outfile)
def index(): args = flask.request.args color = flask.request.values.get("color", "black") p = create_plot(300, np.sin, np.cos, color=color) plot_resources = RESOURCES.render( js_raw=INLINE.js_raw, css_raw=INLINE.css_raw, js_files=INLINE.js_files, css_files=INLINE.css_files, ) script, div = components(p, INLINE) html = flask.render_template('embed.html', plot_script=script, plot_div=div, plot_resources=plot_resources, color=color) return encode_utf8(html)
def root(): resources = Resources("inline") scatter = scatter_example() scatter_el = VBox(children=[HBox(children=[scatter])]) plot_script, plot_div = components(scatter_el, resources) plot_resources = RESOURCES.render( js_raw=resources.js_raw, css_raw=resources.css_raw, js_files=resources.js_files, css_files=resources.css_files, ) html = render_template("test.html", plot_resources=plot_resources, plot_script=plot_script, plot_div=plot_div) return encode_utf8(html)
def root(): resources = Resources("inline") scatter = scatter_example() scatter_el = VBox(children=[HBox(children=[scatter])]) plot_script, plot_div = components(scatter_el, resources) plot_resources = RESOURCES.render( js_raw = resources.js_raw, css_raw = resources.css_raw, js_files = resources.js_files, css_files = resources.css_files, ) html = render_template("test.html", plot_resources = plot_resources, plot_script = plot_script, plot_div = plot_div ) return encode_utf8(html)
def root(): """ Returns the spectrogram of audio data served from /data """ spectrogram = make_spectrogram() resources = Resources("inline") plot_resources = RESOURCES.render( js_raw=resources.js_raw, css_raw=resources.css_raw, js_files=resources.js_files, css_files=resources.css_files, ) plot_script, plot_div = components(spectrogram, resources) html = flask.render_template( "spectrogram.html", plot_resources=plot_resources, plot_script=plot_script, plot_div=plot_div, ) return encode_utf8(html)
def extract_zip(zip_name, exclude_term=None): """Extracts a zip file to its containing directory.""" zip_dir = os.path.dirname(os.path.abspath(zip_name)) try: with zipfile.ZipFile(zip_name) as z: # write each zipped file out if it isn't a directory files = [ zip_file for zip_file in z.namelist() if not zip_file.endswith('/') ] print('Extracting %i files from %r.' % (len(files), zip_name)) for zip_file in files: # remove any provided extra directory term from zip file if exclude_term: dest_file = zip_file.replace(exclude_term, '') else: dest_file = zip_file dest_file = os.path.normpath(os.path.join(zip_dir, dest_file)) dest_dir = os.path.dirname(dest_file) # make directory if it does not exist if not os.path.isdir(dest_dir): os.makedirs(dest_dir) # read file from zip, then write to new directory data = z.read(zip_file) with open(dest_file, 'wb') as f: f.write(encode_utf8(data)) except zipfile.error as e: print("Bad zipfile (%r): %s" % (zip_name, e)) raise e
def polynomial(): """ Very simple embedding of a polynomial chart""" # Grab the inputs arguments from the URL # This is automated by the button args = flask.request.args # Get all the form arguments in the url with defaults color = colors[getitem(args, 'color', 'Black')] _from = int(getitem(args, '_from', 0)) to = int(getitem(args, 'to', 10)) # Create a polynomial line graph x = list(range(_from, to + 1)) fig = figure(title="Polynomial") fig.line(x, [i**2 for i in x], color=color, line_width=2) # Configure resources to include BokehJS inline in the document. # For more details see: # http://bokeh.pydata.org/en/latest/docs/reference/resources_embedding.html#module-bokeh.resources plot_resources = RESOURCES.render( js_raw=INLINE.js_raw, css_raw=INLINE.css_raw, js_files=INLINE.js_files, css_files=INLINE.css_files, ) # For more details see: # http://bokeh.pydata.org/en/latest/docs/user_guide/embedding.html#components script, div = components(fig, INLINE) html = flask.render_template('embed.html', plot_script=script, plot_div=div, plot_resources=plot_resources, color=color, _from=_from, to=to) return encode_utf8(html)
def index(): args = flask.request.args selected_team = flask.request.values.get("selected_team", "LAA") selected_year = int(flask.request.values.get("selected_year", "2012")) p = create_plot(selected_team, selected_year) plot_resources = RESOURCES.render( js_raw=INLINE.js_raw, css_raw=INLINE.css_raw, js_files=INLINE.js_files, css_files=INLINE.css_files, ) script, div = components(p, INLINE) html = flask.render_template( 'embed.html', plot_script=script, plot_div=div, plot_resources=plot_resources, selected_team=selected_team, selected_year=selected_year, years=distinct_years, teams=distinct_teams, ) return encode_utf8(html)
def root(): """ Returns the spectrogram of audio data served from /data """ spectrogram = make_spectrogram() resources = Resources("inline") plot_resources = RESOURCES.render( js_raw = resources.js_raw, css_raw = resources.css_raw, js_files = resources.js_files, css_files = resources.css_files, ) plot_script, plot_div = components( spectrogram, resources ) html = flask.render_template( "spectrogram.html", plot_resources = plot_resources, plot_script = plot_script, plot_div = plot_div, ) return encode_utf8(html)
def set(self, key, val): _data = shelve.open('bokeh.server') key = encode_utf8(key) _data[key] = json.dumps(val) _data.close()
def modelkey(typename, docid, modelid): docid = encode_utf8(docid) modelid = encode_utf8(modelid) return 'bbmodel:%s:%s:%s' % (typename, docid, modelid)
def dockey(docid): docid = encode_utf8('doc:' + docid) return docid