Skip to content

Instantly share code, notes, and snippets.

@xor-xor
Last active August 29, 2015 14:06
Show Gist options
  • Save xor-xor/405e8667c6b44bcb2c79 to your computer and use it in GitHub Desktop.
Save xor-xor/405e8667c6b44bcb2c79 to your computer and use it in GitHub Desktop.
example for line_chart
#!/usr/bin/env python
import json
import requests
API_KEY = 'xxx'
API_URL = 'http://127.0.0.1:7272/api/v0.1/{}'.format(API_KEY)
API_URL_PUSH = '/'.join((API_URL, 'push'))
API_URL_TILECONFIG = '/'.join((API_URL, 'tileconfig'))
TILE_TEMPLATE = 'line_chart'
TILE_KEY = 'line_chart_test'
def main():
# sending data
data = {
"subtitle": "subtitle",
"description": "description",
"series_list": [[["2014-09-16", 1000], ["2014-09-17", 0], ["2014-09-18", 1000]]],
}
data_jsoned = json.dumps(data)
data_to_push = {
'tile': TILE_TEMPLATE,
'key': TILE_KEY,
'data': data_jsoned,
}
resp = requests.post(API_URL_PUSH, data=data_to_push)
if resp.status_code != 200:
print(resp.text)
return
# sending config
tile_config = {
"seriesDefaults": {
"trendline": {"color": "white", "show": True}
}
}
tile_config_jsoned = json.dumps(tile_config)
data_to_push = {
'value': tile_config_jsoned,
}
resp = requests.post(
'/'.join((API_URL_TILECONFIG, TILE_KEY)),
data=data_to_push,
)
if resp.status_code != 200:
print(resp.text)
return
if __name__ == '__main__':
main()
details:
page_title: Testing Dashboard
layout:
- row_1_of_2:
- col_1_of_2:
- tile_template: line_chart
tile_id: line_chart_test
title: xxx
classes:
- col_1_of_2:
- tile_template: empty
tile_id: empty
title: Empty Tile
classes:
- row_1_of_2:
- col_1_of_2:
- tile_template: empty
tile_id: empty
title: Empty Tile
classes:
- col_1_of_2:
- tile_template: empty
tile_id: empty
title: Empty Tile
classes:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment