-
-
Save arikfr/c01fdb6f1b979854ba48 to your computer and use it in GitHub Desktop.
re:dash "client"
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 time | |
import hashlib | |
import hmac | |
import requests | |
def sign(key, path, expires): | |
if not key: | |
return None | |
h = hmac.new(str(key), msg=path, digestmod=hashlib.sha1) | |
h.update(str(expires)) | |
return h.hexdigest() | |
def get_query(redash_url, query_id, secret_api_key): | |
path = '/api/queries/{}/results.json'.format(query_id) | |
expires = time.time()+900 # expires must be <= 3600 seconds from now | |
signature = sign(secret_api_key, path, expires) | |
full_path = "{0}{1}?signature={2}&expires={3}".format(redash_url, path, | |
signature, expires) | |
return requests.get(full_path).json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment