Package pyechonest :: Module results
[hide private]
[frames] | no frames]

Source Code for Module pyechonest.results

 1  #!/usr/bin/env python 
 2  # encoding: utf-8 
 3   
 4  """ 
 5  Copyright (c) 2010 The Echo Nest. All rights reserved. 
 6  Created by Tyler Williams on 2010-04-25. 
 7  """ 
 8   
 9  import logging 
10  from util import attrdict 
11   
12  # I want a: 
13  #   generic object that takes a dict and turns it into an object 
14  #   should take on the name of a key in the dict 
15  #   should handle lists 
16 -class Result(attrdict):
17 - def __init__(self, result_type, result_dict):
18 self._object_type = result_type 19 assert(isinstance(result_dict,dict)) 20 self.__dict__.update(result_dict)
21
22 - def __repr__(self):
23 return "<Result - %s>" % (self._object_type)
24
25 - def __str__(self):
26 return "<Result - %s>" % (self._object_type)
27
28 -def make_results(result_type, response, accessor_function):
29 try: 30 data = accessor_function(response) 31 if isinstance(data, list): 32 return [Result(result_type, item) for item in data] 33 elif isinstance(data, dict): 34 return Result(result_type, data) 35 else: 36 return data 37 except IndexError: 38 logging.info("No songs found")
39