def _send_to_plotly(figure, **supplied_plot_options): """ """ plot_options = dict() plot_options.update(tools._DEFAULT_PLOT_OPTIONS) plot_options.update(_plot_options) plot_options.update(supplied_plot_options) data = json.dumps(figure['data'] if 'data' in figure else [], cls=utils._plotlyJSONEncoder) file_credentials = tools.get_credentials_file() if ('username' in _credentials) and ('api_key' in _credentials): username, api_key = _credentials['username'], _credentials['api_key'] elif ('username' in file_credentials) and ('api_key' in file_credentials): (username, api_key) = (file_credentials['username'], file_credentials['api_key']) else: raise exceptions.PlotlyAccountError("Couldn't find a username, " "api_key pair.") kwargs = json.dumps(dict( filename=plot_options['filename'], fileopt=plot_options['fileopt'], world_readable=plot_options['world_readable'], layout=figure['layout'] if 'layout' in figure else {}), cls=utils._plotlyJSONEncoder) payload = dict( platform= 'python', # TODO: It'd be cool to expose the platform for RaspPi and others version=__version__, args=data, un=username, key=api_key, origin='plot', kwargs=kwargs) url = _plotly_url r = requests.post(url, data=payload) r.raise_for_status() r = json.loads(r.text) if 'error' in r and r['error'] != '': print(r['error']) if 'warning' in r and r['warning'] != '': warnings.warn(r['warning']) if 'message' in r and r['message'] != '': print(r['message']) return r
def _send_to_plotly(figure, **supplied_plot_options): """ """ plot_options = dict() plot_options.update(tools._DEFAULT_PLOT_OPTIONS) plot_options.update(_plot_options) plot_options.update(supplied_plot_options) data = json.dumps(figure['data'] if 'data' in figure else [], cls=utils._plotlyJSONEncoder) file_credentials = tools.get_credentials_file() if ('username' in _credentials) and ('api_key' in _credentials): username, api_key = _credentials['username'], _credentials['api_key'] elif ('username' in file_credentials) and ('api_key' in file_credentials): (username, api_key) = (file_credentials['username'], file_credentials['api_key']) else: raise exceptions.PlotlyAccountError("Couldn't find a username, " "api_key pair.") kwargs = json.dumps(dict(filename=plot_options['filename'], fileopt=plot_options['fileopt'], world_readable=plot_options['world_readable'], layout=figure['layout'] if 'layout' in figure else {}), cls=utils._plotlyJSONEncoder) payload = dict(platform='python', # TODO: It'd be cool to expose the platform for RaspPi and others version=__version__, args=data, un=username, key=api_key, origin='plot', kwargs=kwargs) url = _plotly_url r = requests.post(url, data=payload) r.raise_for_status() r = json.loads(r.text) if 'error' in r and r['error'] != '': print(r['error']) if 'warning' in r and r['warning'] != '': warnings.warn(r['warning']) if 'message' in r and r['message'] != '': print(r['message']) return r
def _validation_key_logic(): creds_on_file = tools.get_credentials_file() if 'username' in _credentials: username = _credentials['username'] elif 'username' in creds_on_file: username = creds_on_file['username'] else: raise exceptions.PlotlyAccountError("Not signed in or no username " "saved in config file") # TODO: a message that doesn't suck if 'api_key' in _credentials: api_key = _credentials['api_key'] elif 'api_key' in creds_on_file: api_key = creds_on_file['api_key'] else: raise exceptions.PlotlyAccountError("Not signed in or no api_key saved " "in config file") # TODO: a message that doesn't suck return (username, api_key)
def _validation_key_logic(): creds_on_file = tools.get_credentials_file() if 'username' in _credentials: username = _credentials['username'] elif 'username' in creds_on_file: username = creds_on_file['username'] else: raise exceptions.PlotlyAccountError( "Not signed in or no username " "saved in config file") # TODO: a message that doesn't suck if 'api_key' in _credentials: api_key = _credentials['api_key'] elif 'api_key' in creds_on_file: api_key = creds_on_file['api_key'] else: raise exceptions.PlotlyAccountError( "Not signed in or no api_key saved " "in config file") # TODO: a message that doesn't suck return (username, api_key)