python-lastfm/src/user.py

149 lines
4.3 KiB
Python
Raw Normal View History

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,
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
self.__stats = stats and Stats(
subject = self,
match = stats.match,
weight = stats.weight
)
2008-07-14 15:50:18 +05:30
def getName(self):
return self.__name
def getUrl(self):
return self.__url
def getImage(self):
return self.__image
def getStats(self):
return self.__stats
2008-07-16 18:36:42 +05:30
2008-07-14 15:50:18 +05:30
name = property(getName, None, None, "Name's Docstring")
url = property(getUrl, None, None, "Url's Docstring")
image = property(getImage, None, None, "Image's Docstring")
stats = property(getStats, None, None, "Weight's Docstring")
2008-07-16 18:36:42 +05:30
2008-07-14 15:50:18 +05:30
def getEvents(self):
pass
events = property(getEvents, None, None, "docstring")
def getFriends(self,
recentTracks = False,
limit = None):
pass
friends = property(getFriends, None, None, "docstring")
def getNeighbours(self, limit = None):
pass
neighbours = property(getNeighbours, None, None, "docstring")
def getPlaylists(self):
pass
playlists = property(getPlaylists, None, None, "docstring")
def getRecentTracks(self, limit = None):
pass
recentTracks = property(getRecentTracks, None, None, "docstring")
def getTopAlbums(self, period = None):
pass
topAlbums = property(getTopAlbums, None, None, "docstring")
topAlbum = property(lambda self: len(self.topAlbums) and self.topAlbums[0],
None, None, "docstring")
def getTopArtists(self, period = None):
pass
topArtists = property(getTopArtists, None, None, "docstring")
topArtist = property(lambda self: len(self.topArtists) and self.topArtists[0],
None, None, "docstring")
def getTopTracks(self, period = None):
pass
topTracks = property(getTopTracks, None, None, "docstring")
topTrack = property(lambda self: len(self.topTracks) and self.topTracks[0],
None, None, "docstring")
def getTopTags(self, limit = None):
pass
topTags = property(getTopTags, None, None, "docstring")
topTag = property(lambda self: len(self.topTags) and self.topTags[0],
None, None, "docstring")
def getWeeklyChartList(self):
pass
def getWeeklyAlbumChart(self,
start = None,
end = None):
pass
weeklyAlbumChart = property(getWeeklyAlbumChart, None, None, "Docstring")
def getWeeklyArtistChart(self,
start = None,
end = None):
pass
weeklyArtistChart = property(getWeeklyArtistChart, None, None, "Docstring")
def getWeeklyTrackChart(self,
start = None,
end = None):
pass
2008-07-15 00:38:39 +05:30
weeklyTrackChart = property(getWeeklyTrackChart, None, None, "Docstring")
@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
from error import LastfmError
from stats import Stats