Esempio n. 1
0
    def read_items(self, buckets=None, results=15, start=0, item_ids=None):
        """
        Returns data from the catalog; also expanded for the requested buckets
        
        Args:
            
        Kwargs:
            buckets (list): A list of strings specifying which buckets to retrieve
            
            results (int): An integer number of results to return
            
            start (int): An integer starting value for the result set
            
        Returns:
            A list of objects in the catalog; list contains additional attributes 'start' and 'total'
        
        Example:

        >>> c
        <catalog - my_songs>
        >>> c.read_items(results=1)
        [<song - Harmonice Mundi II>]
        >>>
        """
        kwargs = {}
        kwargs['bucket'] = buckets or []
        kwargs['item_id'] = item_ids or []
        response = self.get_attribute("read",
                                      results=results,
                                      start=start,
                                      **kwargs)
        rval = ResultList([])
        if item_ids:
            rval.start = 0
            rval.total = len(response['catalog']['items'])
        else:
            rval.start = response['catalog']['start']
            rval.total = response['catalog']['total']
        for item in response['catalog']['items']:
            new_item = None
            # song items
            if 'song_id' in item:
                item['id'] = item.pop('song_id')
                item['title'] = item.pop('song_name')
                request = item['request']
                new_item = song.Song(**util.fix(item))
                new_item.request = request
            # artist item
            elif 'artist_id' in item:
                item['id'] = item.pop('artist_id')
                item['name'] = item.pop('artist_name')
                request = item['request']
                new_item = artist.Artist(**util.fix(item))
                new_item.request = request
            # unresolved item
            else:
                new_item = item
            rval.append(new_item)
        return rval
Esempio n. 2
0
    def read_items(self, buckets=None, results=15, start=0,item_ids=None):
        """
        Returns data from the catalog; also expanded for the requested buckets.
        This method is provided for backwards-compatibility

        Args:

        Kwargs:
            buckets (list): A list of strings specifying which buckets to retrieve

            results (int): An integer number of results to return

            start (int): An integer starting value for the result set

        Returns:
            A list of objects in the catalog; list contains additional attributes 'start' and 'total'

        Example:

        >>> c
        <catalog - my_songs>
        >>> c.read_items(results=1)
        [<song - Harmonice Mundi II>]
        >>>
        """
        warnings.warn("catalog.read_items() is depreciated. Please use catalog.get_item_dicts() instead.")
        kwargs = {}
        kwargs['bucket'] = buckets or []
        kwargs['item_id'] = item_ids or []
        response = self.get_attribute("read", results=results, start=start, **kwargs)
        rval = ResultList([])
        if item_ids:
            rval.start=0;
            rval.total=len(response['catalog']['items'])
        else:
            rval.start = response['catalog']['start']
            rval.total = response['catalog']['total']
        for item in response['catalog']['items']:
            new_item = None
            # song items
            if 'song_id' in item:
                item['id'] = item.pop('song_id')
                item['title'] = item.pop('song_name')
                request = item['request']
                new_item = song.Song(**util.fix(item))
                new_item.request = request
            # artist item
            elif 'artist_id' in item:
                item['id'] = item.pop('artist_id')
                item['name'] = item.pop('artist_name')
                request = item['request']
                new_item = artist.Artist(**util.fix(item))
                new_item.request = request
            # unresolved item
            else:
                new_item = item
            rval.append(new_item)
        return rval
Esempio n. 3
0
    def get_item_dicts(self, buckets=None, results=15, start=0, item_ids=None):
        """
        Returns data from the catalog; also expanded for the requested buckets

        Args:

        Kwargs:
            buckets (list): A list of strings specifying which buckets to retrieve

            results (int): An integer number of results to return

            start (int): An integer starting value for the result set

        Returns:
            A list of dicts representing objects in the catalog; list has additional attributes 'start' and 'total'

        Example:

        >>> c
        <catalog - my_songs>
        >>> c.read_items(results=1)
        [
                {
                    "artist_id": "AR78KRI1187B98E6F2",
                    "artist_name": "Art of Noise",
                    "date_added": "2012-04-02T16:50:02",
                    "foreign_id": "CAHLYLR13674D1CF83:song:1000",
                    "request": {
                        "artist_name": "The Art Of Noise",
                        "item_id": "1000",
                        "song_name": "Love"
                    },
                    "song_id": "SOSBCTO1311AFE7AE0",
                    "song_name": "Love"
                }
        ]
        """
        kwargs = {}
        kwargs['bucket'] = buckets or []
        kwargs['item_id'] = item_ids or []
        response = self.get_attribute("read",
                                      results=results,
                                      start=start,
                                      **kwargs)
        rval = ResultList(response['catalog']['items'])
        if item_ids:
            rval.start = 0
            rval.total = len(response['catalog']['items'])
        else:
            rval.start = response['catalog']['start']
            rval.total = response['catalog']['total']
        return rval
Esempio n. 4
0
    def get_item_dicts(self, buckets=None, results=15, start=0,item_ids=None):
        """
        Returns data from the catalog; also expanded for the requested buckets

        Args:

        Kwargs:
            buckets (list): A list of strings specifying which buckets to retrieve

            results (int): An integer number of results to return

            start (int): An integer starting value for the result set

        Returns:
            A list of dicts representing objects in the catalog; list has additional attributes 'start' and 'total'

        Example:

        >>> c
        <catalog - my_songs>
        >>> c.read_items(results=1)
        [
                {
                    "artist_id": "AR78KRI1187B98E6F2",
                    "artist_name": "Art of Noise",
                    "date_added": "2012-04-02T16:50:02",
                    "foreign_id": "CAHLYLR13674D1CF83:song:1000",
                    "request": {
                        "artist_name": "The Art Of Noise",
                        "item_id": "1000",
                        "song_name": "Love"
                    },
                    "song_id": "SOSBCTO1311AFE7AE0",
                    "song_name": "Love"
                }
        ]
        """
        kwargs = {}
        kwargs['bucket'] = buckets or []
        kwargs['item_id'] = item_ids or []
        response = self.get_attribute("read", results=results, start=start, **kwargs)
        rval = ResultList(response['catalog']['items'])
        if item_ids:
            rval.start=0;
            rval.total=len(response['catalog']['items'])
        else:
            rval.start = response['catalog']['start']
            rval.total = response['catalog']['total']
        return rval