22
22
import copy
23
23
import base64
24
24
import os
25
- from .. import utils
25
+ from .. import utils # TODO make non-relative
26
26
from .. import tools
27
27
from .. import exceptions
28
28
from .. import version
42
42
43
43
_plot_options = dict ()
44
44
45
+ ### test file permissions and make sure nothing is corrupted ###
46
+ tools .ensure_local_plotly_files ()
47
+
45
48
### _credentials stuff ###
46
49
50
+
47
51
def sign_in (username , api_key ):
48
52
"""Set module-scoped _credentials for session. Verify with plotly."""
49
53
global _credentials
50
54
_credentials ['username' ], _credentials ['api_key' ] = username , api_key
51
55
# TODO: verify these _credentials with plotly
52
56
53
57
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 ###
70
59
71
60
def update_plot_options (** kwargs ):
72
61
""" Update the module-level _plot_options
@@ -316,7 +305,7 @@ def get_figure(file_owner, file_id, raw=False):
316
305
"There was an error retrieving this file" )
317
306
318
307
319
- @utils .template_doc (plotly_domain = tools ._get_plotly_urls ( forgiving = True )[ 0 ] )
308
+ @utils .template_doc (** tools .get_config_file () )
320
309
class Stream :
321
310
""" Interface to Plotly's real-time graphing API.
322
311
@@ -344,7 +333,7 @@ class Stream:
344
333
>>> stream.write(dict(x=1, y=1)) # Plot (1, 1) in your graph
345
334
"""
346
335
347
- @utils .template_doc (plotly_domain = tools ._get_plotly_urls ( forgiving = True )[ 0 ] )
336
+ @utils .template_doc (** tools .get_config_file () )
348
337
def __init__ (self , stream_id ):
349
338
""" Initialize a Stream object with your unique stream_id.
350
339
Find your stream_id at {plotly_domain}/settings.
@@ -364,13 +353,12 @@ def open(self):
364
353
http://nbviewer.ipython.org/github/plotly/python-user-guide/blob/master/s7_streaming/s7_streaming.ipynb
365
354
"""
366
355
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 ,
369
358
80 ,
370
- {'Host' : plotly_streaming_url ,
359
+ {'Host' : streaming_url ,
371
360
'plotly-streamtoken' : self .stream_id })
372
361
373
-
374
362
def write (self , data , layout = None , validate = True ,
375
363
reconnect_on = (200 , '' , 408 )):
376
364
""" Write `data` to your stream. This will plot the
@@ -473,7 +461,7 @@ def get(figure):
473
461
'plotly-version' : '2.0' ,
474
462
'plotly-platform' : 'python' }
475
463
476
- url = tools ._get_plotly_urls ()[0 ] + "/apigenimage/"
464
+ url = tools .get_config_file ()['plotly_domain' ] + "/apigenimage/"
477
465
res = requests .post (url ,
478
466
data = json .dumps (figure ,
479
467
cls = utils ._plotlyJSONEncoder ),
@@ -546,7 +534,7 @@ def _send_to_plotly(figure, **plot_options):
546
534
origin = 'plot' ,
547
535
kwargs = kwargs )
548
536
549
- url = tools ._get_plotly_urls ()[0 ] + "/clientresp"
537
+ url = tools .get_config_file ()['plotly_domain' ] + "/clientresp"
550
538
551
539
r = requests .post (url , data = payload )
552
540
r .raise_for_status ()
0 commit comments