Last active
December 2, 2016 19:35
-
-
Save mdtusz/7ebb0064d04b0beb6e26cdbec888092d to your computer and use it in GitHub Desktop.
Copy cloud plots to a local streambed install.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import pprint | |
import plotly.plotly as py | |
import plotly.graph_objs as go | |
import requests | |
# These will only work locally. Don't have a cow lol. | |
LOCAL_USERNAME = 'cats' | |
LOCAL_API_KEY = 'oMHrgprVMhZZLOttM0j8' | |
LOCAL_API_ENDPOINT = 'https://api-local.plot.ly/v2' | |
pp = pprint.PrettyPrinter(indent=4) | |
def copy(fid, filename): | |
py.sign_in( | |
LOCAL_USERNAME, LOCAL_API_KEY, | |
plotly_domain='https://local.plot.ly', | |
plotly_api_domain=LOCAL_API_ENDPOINT | |
) | |
url = 'https://plot.ly/{}.json'.format(fid) | |
try: | |
plot = requests.get(url).json() | |
except Error: | |
print ' '.join([ | |
'Who\'s the goose! Looks like that plot is private or something.', | |
'Double check and try again.' | |
]) | |
return | |
plot['data'] = plot['data'] if 'data' in plot else [] | |
plot['layout'] = plot['layout'] if 'layout' in plot else {} | |
fig = go.Figure(data=plot['data'], layout=plot['layout']) | |
py.plot(fig, auto_open=False, filename=filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment