1
2
3 __author__ = "Abhinav Sarkar <abhinav@abhinavsarkar.net>"
4 __version__ = "0.2"
5 __license__ = "GNU Lesser General Public License"
8 """A class representing a tasteometer."""
9 - def __init__(self,
10 score = None,
11 matches = None,
12 artists = None):
16
17 @property
19 """score of the comparison"""
20 return self._score
21
22 @property
24 """matches for the comparison"""
25 return self._matches
26
27 @property
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
64 return "<lastfm.Tasteometer: %s%% match>" % (self.score*100)
65
66 from lastfm.artist import Artist
67