Package lastfm :: Module tasteometer

[hide private]
[frames] | no frames]

# Source Code for Module lastfm.tasteometer

     1  #!/usr/bin/env python
     2
     3  __author__ = "Abhinav Sarkar <abhinav@abhinavsarkar.net>"
     4  __version__ = "0.2"
     5  __license__ = "GNU Lesser General Public License"
     6
     7 -class Tasteometer(object):
     8      """A class representing a tasteometer."""
     9 -    def __init__(self,
    10                   score = None,
    11                   matches = None,
    12                   artists = None):
    13          self._score = score
    14          self._matches = matches
    15          self._artists = artists
    16
    17      @property
    18 -    def score(self):
    19          """score of the comparison"""
    20          return self._score
    21
    22      @property
    23 -    def matches(self):
    24          """matches for the comparison"""
    25          return self._matches
    26
    27      @property
    28 -    def artists(self):
    29          """artists for the comparison"""
    30          return self._artists
    31
    32      @staticmethod
    33 -    def compare(api,
    34                  type1, type2,
    35                  value1, value2,
    36                  limit = None):
    37          params = {
    38                    'method': 'tasteometer.compare',
    39                    'type1': type1,
    40                    'type2': type2,
    41                    'value1': value1,
    42                    'value2': value2
    43                    }
    44          if limit is not None:
    45              params.update({'limit': limit})
    46          data = api._fetch_data(params).find('comparison/result')
    47          return Tasteometer(
    48                             score = float(data.findtext('score')),
    49                             matches = int(data.find('artists').attrib['matches']),
    50                             artists = [
    51                                        Artist(
    52                                                api,
    53                                                name = a.findtext('name'),
    54                                                url = a.findtext('url'),
    55                                                image = dict([(i.get('size'), i.text) for i in a.findall('image')]),
    56                                                )
    57                                        for a in data.findall('artists/artist')
    58                                        ]
    59                             )
    60
    61
    62
    63 -    def __repr__(self):
    64          return "<lastfm.Tasteometer: %s%% match>" % (self.score*100)
    65
    66  from lastfm.artist import Artist
    67