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
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import requests\n",
"base = 'https://api.clever.com/'\n",
"api = base + 'v1.1/'\n",
"token = 'DEMO_TOKEN'"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 15
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"auth = {\"Authorization\": \"Bearer \"+token}\n",
"r = requests.get(base+'me', headers=auth)\n",
"r.text"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 5,
"text": [
"u'{\"data\":{\"name\":\"Demo District\",\"id\":\"4fd43cc56d11340000000005\"},\"type\":\"district\"}'"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"r = requests.get(api+'districts', headers=auth)\n",
"districts = [d['data'] for d in r.json()['data']]\n",
"district_id = districts[0]['id']\n",
"district_id"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 16,
"text": [
"u'4fd43cc56d11340000000005'"
]
}
],
"prompt_number": 16
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"url = api+'districts/'+district_id+'/sections'\n",
"r = requests.get(url, headers=auth)\n",
"from pprint import pprint\n",
"sections = r.json()['data']\n",
"count_sections = len(sections)\n",
"count_students = sum([len(section['data']['students']) for section in sections])\n",
"count_students / float(count_sections)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 37,
"text": [
"21.8"
]
}
],
"prompt_number": 37
}
],
"metadata": {}
}
]
}
# -*- 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