Skip to content

Instantly share code, notes, and snippets.

@lardcanoe
Created April 21, 2015 22:40
Show Gist options
  • Save lardcanoe/78e01e1dad42f55a951f to your computer and use it in GitHub Desktop.
Save lardcanoe/78e01e1dad42f55a951f to your computer and use it in GitHub Desktop.
Access Health Check Pulse through API
#!/usr/bin/env python
import urlparse
import urllib2
import json
import os
import pprint
API_ENDPOINT = "https://chapi.cloudhealthtech.com/pulse/"
API_KEY = os.getenv('API_KEY')
# Returns json for requested report.
def get_pulse(report, api_key):
uri = urlparse.urljoin(API_ENDPOINT, report)
uri += "?api_key=%s" % API_KEY
request = urllib2.Request(uri, headers={"Accept" : "application/json"})
response = urllib2.urlopen(request)
page = response.read()
return json.loads(page)
# Fetch the json for the report
try:
data = get_pulse("health-check-data", API_KEY)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(data['health_check_pulse'])
except urllib2.HTTPError as e:
print e.code
print e.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment