Skip to content

Add a get_plot_url_by_path beta function. #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plotly/plotly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
grid_ops,
meta_ops,
file_ops,
get_config
get_config,
get_plot_url_by_path
)
25 changes: 25 additions & 0 deletions plotly/plotly/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,3 +1421,28 @@ def _open_url(url):
wbopen(url)
except: # TODO: what should we except here? this is dangerous
pass


def get_plot_url_by_path(path, user=None, parent=None):
"""
Get the share url of a plot based on the path of the file.

THIS FUNCTION IS IN BETA! It may change or move without warning.

:param (str) path: Partial file path (can just be the filename)
:param (str) user: The username of the plotly user who owns the file.
:param (int) parent: The id of the parent folder. E.g, home folder is `-1`.
:raises: (PlotlyError) If underlying api request fails.
:return: (str) The url for the plot. This can be passed to get_figure()

"""
url = _api_v2.api_url('plots/lookup')
query_string = '?path={}'.format(path)
if user is not None:
query_string += '&user={}'.format(user)
if parent is not None:
query_string == '&parent={}'.format(parent)
headers = _api_v2.headers()
response = requests.get('{}{}'.format(url, query_string), headers=headers)
response_dict = _api_v2.response_handler(response)
return response_dict['web_url']