Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 938baf7

Browse files
committed
updated plotly.py to use new syntax and tools.get_config_file().
(also deleted some things that were commented out)
1 parent 093f9dc commit 938baf7

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

plotly/plotly/plotly.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import copy
2323
import base64
2424
import os
25-
from .. import utils
25+
from .. import utils # TODO make non-relative
2626
from .. import tools
2727
from .. import exceptions
2828
from .. import version
@@ -42,31 +42,20 @@
4242

4343
_plot_options = dict()
4444

45+
### test file permissions and make sure nothing is corrupted ###
46+
tools.ensure_local_plotly_files()
47+
4548
### _credentials stuff ###
4649

50+
4751
def sign_in(username, api_key):
4852
"""Set module-scoped _credentials for session. Verify with plotly."""
4953
global _credentials
5054
_credentials['username'], _credentials['api_key'] = username, api_key
5155
# TODO: verify these _credentials with plotly
5256

5357

54-
### _plot_options stuff ###
55-
56-
# def load_plot_options():
57-
# """ Import the plot_options from file into the module-level _plot_options.
58-
# """
59-
# global _plot_options
60-
# _plot_options = _plot_options.update(tools.get_plot_options_file())
61-
#
62-
#
63-
# def save_plot_options(**kwargs):
64-
# """ Save the module-level _plot_options to file for later access
65-
# """
66-
# global _plot_options
67-
# update_plot_options(**kwargs)
68-
# tools.save_plot_options_file(**_plot_options)
69-
58+
### plot options stuff ###
7059

7160
def update_plot_options(**kwargs):
7261
""" Update the module-level _plot_options
@@ -316,7 +305,7 @@ def get_figure(file_owner, file_id, raw=False):
316305
"There was an error retrieving this file")
317306

318307

319-
@utils.template_doc(plotly_domain=tools._get_plotly_urls(forgiving=True)[0])
308+
@utils.template_doc(**tools.get_config_file())
320309
class Stream:
321310
""" Interface to Plotly's real-time graphing API.
322311
@@ -344,7 +333,7 @@ class Stream:
344333
>>> stream.write(dict(x=1, y=1)) # Plot (1, 1) in your graph
345334
"""
346335

347-
@utils.template_doc(plotly_domain=tools._get_plotly_urls(forgiving=True)[0])
336+
@utils.template_doc(**tools.get_config_file())
348337
def __init__(self, stream_id):
349338
""" Initialize a Stream object with your unique stream_id.
350339
Find your stream_id at {plotly_domain}/settings.
@@ -364,13 +353,12 @@ def open(self):
364353
http://nbviewer.ipython.org/github/plotly/python-user-guide/blob/master/s7_streaming/s7_streaming.ipynb
365354
"""
366355

367-
plotly_streaming_url = tools._get_plotly_urls(forgiving=True)[1]
368-
self._stream = chunked_requests.Stream(plotly_streaming_url,
356+
streaming_url = tools.get_config_file()['plotly_streaming_domain']
357+
self._stream = chunked_requests.Stream(streaming_url,
369358
80,
370-
{'Host': plotly_streaming_url,
359+
{'Host': streaming_url,
371360
'plotly-streamtoken': self.stream_id})
372361

373-
374362
def write(self, data, layout=None, validate=True,
375363
reconnect_on=(200, '', 408)):
376364
""" Write `data` to your stream. This will plot the
@@ -473,7 +461,7 @@ def get(figure):
473461
'plotly-version': '2.0',
474462
'plotly-platform': 'python'}
475463

476-
url = tools._get_plotly_urls()[0] + "/apigenimage/"
464+
url = tools.get_config_file()['plotly_domain'] + "/apigenimage/"
477465
res = requests.post(url,
478466
data=json.dumps(figure,
479467
cls=utils._plotlyJSONEncoder),
@@ -546,7 +534,7 @@ def _send_to_plotly(figure, **plot_options):
546534
origin='plot',
547535
kwargs=kwargs)
548536

549-
url = tools._get_plotly_urls()[0] + "/clientresp"
537+
url = tools.get_config_file()['plotly_domain'] + "/clientresp"
550538

551539
r = requests.post(url, data=payload)
552540
r.raise_for_status()

0 commit comments

Comments
 (0)