Skip to content

Instantly share code, notes, and snippets.

@arikfr
Created January 15, 2015 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arikfr/c01fdb6f1b979854ba48 to your computer and use it in GitHub Desktop.
Save arikfr/c01fdb6f1b979854ba48 to your computer and use it in GitHub Desktop.
re:dash "client"
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