Created
January 31, 2017 08:48
-
-
Save danromero/20e4ee99ae1c48dc813105786c9990df to your computer and use it in GitHub Desktop.
This file contains hidden or 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 json | |
import pygal | |
from requests_oauthlib import OAuth1Session | |
desk = OAuth1Session('client', | |
client_secret='XXX', | |
resource_owner_key='XXX', | |
resource_owner_secret='XXX') | |
url = 'https://yourdomain.desk.com/api/v2/insights3/reports' | |
data = '{"fields": ["case_creates", "case_resolves"], "time": {"min": "2015-01-01T00:00:00-08:00", "max": "2017-01-15T00:00:00-08:00", "window_size": "month"}}' | |
r = desk.post(url, data=data) | |
x = r.json() | |
dx = x['data'] | |
date = [] | |
created_data = [] | |
resolve_data = [] | |
for item in dx: | |
date.append(item[0]) | |
for item in dx: | |
created_data.append(item[3]) | |
for item in dx: | |
resolve_data.append(item[4]) | |
line_chart = pygal.Line() | |
line_chart.title = 'Cases and Resolved over time' | |
line_chart.x_labels = map(str, date) | |
line_chart.add('Created', created_data) | |
line_chart.add('Resolved', resolve_data) | |
line_chart.render_in_browser() | |
print('Completed!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment