def requestWithUserAndParams(user, params): import sb_helpers as sh import what.whathelpers as wh wp = wh.whatPlug(user) try: action = params['action'][0] except KeyError as e: return ['No action found for params'] req = None if action =='artists': req = [] soup = wp.wrap() artists = soup.artist.all() for art in artists: i = art.id gids =map(lambda x: x.gid, soup.artist_gids.filter_by(artist=i).all()) for g in gids: req.append({'artist_mbid':g,'name':art.name}) elif action =='albums': soup = wp.wrap() req = map(lambda x: x.name, id.release.all()) else: raise Exception('unimplemented action: '+action) for r in req: r['datatype'] =sh.dtFromAction(action) for r in req: r['action'] = action return req
def requestWithUserAndParams(user, params): #for now, the user key is meaningless action = params['action'][0] import dbs.mbrainz.fetchMB as fm src_module = fm req = None if action == 'albums': tryfilter = 'artist_mbid' if req == None and tryfilter in params.keys(): req = src_module.getMBIDArtistAlbums(params[tryfilter]) if req == None: req = src_module.getAllAlbums() print 'request: ' + str(req) elif action =='artists': req = src_module.getAllArtists(); elif action =='members': tryfilter = 'album_mbid' if req == None and tryfilter in params.keys(): req = src_module.getMBIDAlbumMembers(params[tryfilter]) tryfilter = 'artist_mbid' if req == None and tryfilter in params.keys(): req = src_module.getMBIDArtistMembers(params[tryfilter]) if req == None: req = src_module.getAllMembers() elif action =='tracks': tryfilter = 'album_mbid' if req ==None and tryfilter in params.keys(): req = src_module.getMBIDAlbumTracks(params[tryfilter]) tryfilter = 'artist_mbid' if req == None and tryfilter in params.keys(): req = src_module.getMBIDArtistTracks(params[tryfilter]) if req == None: req = src_module.getAllTracks() if req == None: raise Exception('unhandled action for request ' + str(params)) for r in req: r['datatype'] =sh.dtFromAction(action) for r in req: r['action'] = action return req
def route(fetcher,params): #for now, the user key is meaningless action = params['action'][0] req = None if action == 'albums': tryfilter = 'artist_mbid' if req == None and tryfilter in params.keys(): req = fetcher.getMBIDArtistAlbums(params[tryfilter][0]) if req == None: req = fetcher.getAllAlbums() print 'request: ' + str(req) elif action =='artists': req = fetcher.getAllArtists(); elif action =='members': tryfilter = 'album_mbid' if req == None and tryfilter in params.keys(): req = fetcher.getMBIDAlbumMembers(params[tryfilter][0]) tryfilter = 'artist_mbid' if req == None and tryfilter in params.keys(): req = fetcher.getMBIDArtistMembers(params[tryfilter][0]) if req == None: req = fetcher.getAllMembers() elif action =='tracks': tryfilter = 'album_mbid' if req ==None and tryfilter in params.keys(): req = fetcher.getMBIDAlbumTracks(params[tryfilter][0]) tryfilter = 'artist_mbid' if req == None and tryfilter in params.keys(): req = fetcher.getMBIDArtistTracks(params[tryfilter][0]) if req == None: req = fetcher.getAllTracks() if req == None: raise Exception('unhandled action for request ' + str(params)) for r in req: r['datatype'] =sh.dtFromAction(action) for r in req: r['action'] = action return req