Skip to content

Instantly share code, notes, and snippets.

@iiSeymour
Last active August 29, 2015 14:05
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 iiSeymour/0c5fe4659be1d26d6ba4 to your computer and use it in GitHub Desktop.
Save iiSeymour/0c5fe4659be1d26d6ba4 to your computer and use it in GitHub Desktop.
Geckoboard Highchart Boxplot
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import requests
__URL__ = "http://push.geckoboard.com/v1/send/"
def push(chart, widgit_id, api_key):
"""
Push a chart to geckoboard to update a widget
Returns tuple HTTP response code and JSON message
"""
packet = json.dumps({"api_key": api_key, "data": {"highchart": chart}})
url = __URL__ + widgit_id
req = requests.post(url, packet)
return req.status_code, req.json()
def boxplot(x, y, title=''):
"""
Return a dictionary describing a highchart boxplot
"""
return {"chart": {"type": "boxplot"},
"title": {"align": "center", "text": title},
"xAxis": {"categories": x},
"yAxis": {"title": {"text": title}},
"series": [{"name": 'Observations', "data": y}]}
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--api-key", required=True, help="geckoboard API key")
parser.add_argument("--widgit-id", required=True, help="widgit ID to update")
args = parser.parse_args()
x = ['1', '2', '3', '4', '5']
y = [[760, 801, 848, 895, 965],
[733, 853, 939, 980, 1080],
[714, 762, 817, 870, 918],
[724, 802, 806, 871, 950],
[834, 836, 864, 882, 910]]
chart = boxplot(x, y, title='Boxplot Test')
response = push(chart, args.widgit_id, args.api_key)
print response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment