def _get_course_block_counts(auth_token, block_url):
 headers = {'Authorization': 'Bearer {}'.format(auth_token)}
 response = requests.get(block_url, headers=headers)
 if (response.status_code != 200):
  print 'url {} returned status code {}'.format(block_url, response.status_code)
  return {}
 response_json = response.json()
 if ((BLOCK_ROOT_KEY in response_json) and (BLOCKS_KEY in response_json)):
  root_val = response_json[BLOCK_ROOT_KEY]
  counts = response_json[BLOCKS_KEY][root_val][BLOCK_COUNTS_KEY]
  return counts
 return {}

def _get_course_block_counts ( auth_token , block_url ) : headers = { 'Authorization' : 'Bearer {}' . format ( auth_token ) } response = requests . get ( block_url , headers = headers ) if ( response . status_code != 200 ) : print 'url {} returned status code {}' . format ( block_url , response . status_code ) return { } response_json = response . json ( ) if ( ( BLOCK_ROOT_KEY in response_json ) and ( BLOCKS_KEY in response_json ) ) : root_val = response_json [ BLOCK_ROOT_KEY ] counts = response_json [ BLOCKS_KEY ] [ root_val ] [ BLOCK_COUNTS_KEY ] return counts return { }
get the block counts for a given block_url arguments: auth_token : the authentication token to access the api block_url : the respective url for a courses xblock data returns: dict: a dictionary containing the block counts .