Skip to content
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

Example script: delete queries #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
153 changes: 117 additions & 36 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ find-tables = "redash_toolbelt.examples.find_table_names:main"
clone-dashboard-and-queries = "redash_toolbelt.examples.clone_dashboard_and_queries:main"
export-queries = "redash_toolbelt.examples.query_export:main"
redash-migrate = "redash_toolbelt.examples.migrate:main"
delete-queries = "redash_toolbelt.examples.delete_queries:main"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really require an example script? If it does, "delete queries" (plural) is the wrong name for it since your example accepts a single query_id (not plural).

Not every example requires an entry under tool.poetry.scripts either. The purpose of examples is to show how to use redash-toolbelt.

I suppose it's okay to have such a simple example here, but it should be named correctly.


[build-system]
requires = ["poetry>=0.12"]
Expand Down
29 changes: 29 additions & 0 deletions redash_toolbelt/examples/delete_queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import click
import requests
from redash_toolbelt.client import Redash

template = u"""/*
API KEY: {name}
*/
{query}"""

Comment on lines +5 to +9
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the purpose of this...

Suggested change
template = u"""/*
API KEY: {name}
*/
{query}"""

@click.command()
@click.argument("redash_url")
@click.argument("query_id")
@click.option(
"--api-key",
"api_key",
required=True,
envvar="REDASH_API_KEY",
show_envvar=True,
prompt="API Key",
help="User API Key",
)

def main(redash_url, api_key, query_id):
redash = Redash(redash_url, api_key)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a docstring here. Users will see it when they call

$ delete-queries --help

path = f'api/queries/{query_id}'
redash._delete(path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a user-facing script, you should catch exceptions explicitly to notify the user whether the operation succeeded or failed.


if __name__ == "__main__":
main()