Skip to content

Commit 52c6cc9

Browse files
committed
Add a get_plot_url_by_path beta function.
User request that’s pretty easy to shoot a tracer bullet out for. We’ll probably want to make a full-on wrapper for the api, but this is useful now and it’s being asked for.
1 parent a4a62e3 commit 52c6cc9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

plotly/plotly/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
grid_ops,
2222
meta_ops,
2323
file_ops,
24-
get_config
24+
get_config,
25+
get_plot_url_by_path
2526
)

plotly/plotly/plotly.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,3 +1421,28 @@ def _open_url(url):
14211421
wbopen(url)
14221422
except: # TODO: what should we except here? this is dangerous
14231423
pass
1424+
1425+
1426+
def get_plot_url_by_path(path, user=None, parent=None):
1427+
"""
1428+
Get the share url of a plot based on the path of the file.
1429+
1430+
THIS FUNCTION IS IN BETA! It may change or move without warning.
1431+
1432+
:param (str) path: Partial file path (can just be the filename)
1433+
:param (str) user: The username of the plotly user who owns the file.
1434+
:param (int) parent: The id of the parent folder. E.g, home folder is `-1`.
1435+
:raises: (PlotlyError) If underlying api request fails.
1436+
:return: (str) The url for the plot. This can be passed to get_figure()
1437+
1438+
"""
1439+
url = _api_v2.api_url('plots/lookup')
1440+
query_string = '?path={}'.format(path)
1441+
if user is not None:
1442+
query_string += '&user={}'.format(user)
1443+
if parent is not None:
1444+
query_string == '&parent={}'.format(parent)
1445+
headers = _api_v2.headers()
1446+
response = requests.get('{}{}'.format(url, query_string), headers=headers)
1447+
response_dict = _api_v2.response_handler(response)
1448+
return response_dict['web_url']

0 commit comments

Comments
 (0)