2008-07-14 15:50:18 +05:30
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
__author__ = "Abhinav Sarkar"
|
|
|
|
__version__ = "0.1"
|
|
|
|
__license__ = "GNU Lesser General Public License"
|
|
|
|
|
2008-07-15 00:38:39 +05:30
|
|
|
from base import LastfmBase
|
|
|
|
|
|
|
|
class User(LastfmBase):
|
2008-07-14 15:50:18 +05:30
|
|
|
"""A class representing an user."""
|
2008-07-16 18:36:42 +05:30
|
|
|
def init(self,
|
2008-07-14 15:50:18 +05:30
|
|
|
api,
|
|
|
|
name = None,
|
|
|
|
url = None,
|
2008-07-16 18:36:42 +05:30
|
|
|
image = None,
|
2008-07-17 22:17:32 +05:30
|
|
|
stats = None):
|
2008-07-16 18:36:42 +05:30
|
|
|
if not isinstance(api, Api):
|
|
|
|
raise LastfmError("api reference must be supplied as an argument")
|
2008-07-14 15:50:18 +05:30
|
|
|
self.__api = api
|
|
|
|
self.__name = name
|
|
|
|
self.__url = url
|
|
|
|
self.__image = image
|
2008-07-17 22:17:32 +05:30
|
|
|
self.__stats = stats and Stats(
|
|
|
|
subject = self,
|
|
|
|
match = stats.match,
|
|
|
|
weight = stats.weight
|
|
|
|
)
|
2008-07-14 15:50:18 +05:30
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""name of the user"""
|
2008-07-14 15:50:18 +05:30
|
|
|
return self.__name
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def url(self):
|
|
|
|
"""url of the user's page"""
|
2008-07-14 15:50:18 +05:30
|
|
|
return self.__url
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def image(self):
|
|
|
|
"""image of the user"""
|
2008-07-14 15:50:18 +05:30
|
|
|
return self.__image
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def stats(self):
|
|
|
|
"""stats for the user"""
|
2008-07-17 22:17:32 +05:30
|
|
|
return self.__stats
|
2008-07-31 16:04:46 +05:30
|
|
|
|
|
|
|
@property
|
|
|
|
def events(self):
|
2008-07-14 15:50:18 +05:30
|
|
|
pass
|
|
|
|
|
|
|
|
def getFriends(self,
|
|
|
|
recentTracks = False,
|
|
|
|
limit = None):
|
|
|
|
pass
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def friends(self):
|
|
|
|
"""friends of the user"""
|
|
|
|
return self.getFriends()
|
2008-07-14 15:50:18 +05:30
|
|
|
|
|
|
|
def getNeighbours(self, limit = None):
|
|
|
|
pass
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def neighbours(self):
|
|
|
|
"""neightbours of the user"""
|
|
|
|
return self.getNeighbours()
|
2008-07-14 15:50:18 +05:30
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def playlists(self):
|
|
|
|
"""playlists of the user"""
|
2008-07-14 15:50:18 +05:30
|
|
|
pass
|
|
|
|
|
|
|
|
def getRecentTracks(self, limit = None):
|
|
|
|
pass
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def recentTracks(self):
|
|
|
|
"""recent tracks played by the user"""
|
|
|
|
return self.getRecentTracks()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def mostRecentTrack(self):
|
|
|
|
"""most recent track played by the user"""
|
|
|
|
return (len(self.recentTracks) and self.recentTracks[0] or None)
|
2008-07-14 15:50:18 +05:30
|
|
|
|
|
|
|
def getTopAlbums(self, period = None):
|
|
|
|
pass
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def topAlbums(self):
|
|
|
|
"""top albums of the user"""
|
|
|
|
return self.getTopAlbums()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def topAlbum(self):
|
|
|
|
"""top album fo the user"""
|
|
|
|
return (len(self.topAlbums) and self.topAlbums[0] or None)
|
2008-07-14 15:50:18 +05:30
|
|
|
|
|
|
|
def getTopArtists(self, period = None):
|
|
|
|
pass
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def topArtists(self):
|
|
|
|
"""top artists of the user"""
|
|
|
|
return self.getTopArtists()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def topArtist(self):
|
|
|
|
"""top artist of the user"""
|
|
|
|
return (len(self.topArtists) and self.topArtists[0] or None)
|
2008-07-14 15:50:18 +05:30
|
|
|
|
|
|
|
def getTopTracks(self, period = None):
|
|
|
|
pass
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def topTracks(self):
|
|
|
|
"""top tracks of the user"""
|
|
|
|
return self.getTopTracks()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def topTrack(self):
|
|
|
|
"""top track of the user"""
|
|
|
|
return (len(self.topTracks) and self.topTracks[0] or None)
|
2008-07-14 15:50:18 +05:30
|
|
|
|
|
|
|
def getTopTags(self, limit = None):
|
|
|
|
pass
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def topTags(self):
|
|
|
|
"""top tags of the user"""
|
|
|
|
return self.getTopTags()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def topTag(self):
|
|
|
|
"""top tag of the user"""
|
|
|
|
return (len(self.topTags) and self.topTags[0] or None)
|
2008-07-14 15:50:18 +05:30
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def weeklyChartList(self):
|
2008-07-14 15:50:18 +05:30
|
|
|
pass
|
|
|
|
|
|
|
|
def getWeeklyAlbumChart(self,
|
|
|
|
start = None,
|
|
|
|
end = None):
|
|
|
|
pass
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def recentWeeklyAlbumChart(self):
|
|
|
|
return self.getWeeklyAlbumChart()
|
2008-07-14 15:50:18 +05:30
|
|
|
|
|
|
|
def getWeeklyArtistChart(self,
|
|
|
|
start = None,
|
|
|
|
end = None):
|
|
|
|
pass
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def recentWeeklyArtistChart(self):
|
|
|
|
return self.getWeeklyArtistChart()
|
2008-07-14 15:50:18 +05:30
|
|
|
|
|
|
|
def getWeeklyTrackChart(self,
|
|
|
|
start = None,
|
|
|
|
end = None):
|
|
|
|
pass
|
|
|
|
|
2008-07-31 16:04:46 +05:30
|
|
|
@property
|
|
|
|
def recentWeeklyTrackChart(self):
|
|
|
|
return self.getWeeklyTrackChart()
|
2008-07-15 00:38:39 +05:30
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def hashFunc(*args, **kwds):
|
|
|
|
try:
|
|
|
|
return hash(kwds['name'])
|
|
|
|
except KeyError:
|
|
|
|
raise LastfmError("name has to be provided for hashing")
|
|
|
|
|
|
|
|
def __hash__(self):
|
|
|
|
return self.__class__.hashFunc(name = self.name)
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
return self.name == other.name
|
|
|
|
|
|
|
|
def __lt__(self, other):
|
|
|
|
return self.name < other.name
|
|
|
|
|
|
|
|
def __repr__(self):
|
2008-07-15 17:29:49 +05:30
|
|
|
return "<lastfm.User: %s>" % self.name
|
2008-07-16 18:36:42 +05:30
|
|
|
|
|
|
|
from api import Api
|
2008-07-17 22:17:32 +05:30
|
|
|
from error import LastfmError
|
|
|
|
from stats import Stats
|