Skip to content

Instantly share code, notes, and snippets.

@glifchits
Last active August 29, 2015 13:57
Show Gist options
  • Save glifchits/9807044 to your computer and use it in GitHub Desktop.
Save glifchits/9807044 to your computer and use it in GitHub Desktop.
IPython notebook interacting with the Clever demo API
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
import requests
base = 'https://api.clever.com/'
api = base + 'v1.1/'
token = 'DEMO_TOKEN'
# <codecell>
auth = {"Authorization": "Bearer "+token}
r = requests.get(base+'me', headers=auth)
r.text
# <codecell>
r = requests.get(api+'districts', headers=auth)
districts = [d['data'] for d in r.json()['data']]
district_id = districts[0]['id']
district_id
# <codecell>
url = api+'districts/'+district_id+'/sections'
r = requests.get(url, headers=auth)
sections = r.json()['data']
count_sections = len(sections)
count_students = sum([len(section['data']['students']) for section in sections])
count_students / float(count_sections)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment