added user and weeklychart modules

master
Abhinav Sarkar 2008-07-14 10:20:18 +00:00
parent 0d055183bc
commit 684315cca4
4 changed files with 190 additions and 1 deletions

View File

@ -170,6 +170,19 @@ class Api(object):
value1, value2,
limit = None):
return Tasteometer(self, type1, type2, value1, value2, limit)
def getTrack(self, name, artist = None):
return Track(self, name = name, artist = artist)
def searchTrack(self,
track,
artist = None,
limit = None,
page = None):
return Track.search(self, track, artist, limit, page)
def getUser(self, name):
return User(self, name = name)
def _fetchUrl(self,
url,

View File

@ -7,6 +7,7 @@ __license__ = "GNU Lesser General Public License"
class Track(object):
"""A class representing a track."""
def __init__(self,
api,
name = None,
mbid = None,
url = None,
@ -14,6 +15,7 @@ class Track(object):
artist = None,
image = None,
match = None):
self.__api = api
self.__name = name
self.__mbid = mbid
self.__url = url
@ -55,4 +57,62 @@ class Track(object):
image = property(getImage, None, None, "Image's Docstring")
match = property(getMatch, None, None, "Match's Docstring")
match = property(getMatch, None, None, "Match's Docstring")
def __checkParams(self,
params,
artist = None,
track = None,
mbid = None):
if not ((artist and track) or mbid):
raise LastfmError("either (artist and track) or mbid has to be given as argument.")
if artist and album:
params.update({'artist': artist, 'track': track})
elif mbid:
params.update({'mbid': mbid})
return params
def getSimilar(self,
artist = None,
track = None,
mbid = None):
params = self.__checkParams({'method': 'track.getsimilar'}, artist, track, mbid)
data = self.__api.fetchData(params).find('similartracks')
similar = property(getSimilar, None, None, "Similar's Docstring")
mostSimilar = property(lambda self: len(self.similar) and self.similar[0],
None, None, "docstring")
def getTopFans(self,
artist = None,
track = None,
mbid = None):
params = self.__checkParams({'method': 'track.gettopfans'}, artist, track, mbid)
data = self.__api.fetchData(params).find('topfans')
topFans = property(getTopFans, None, None, "top fans's Docstring")
topFan = property(lambda self: len(self.topFans) and self.topFans[0],
None, None, "docstring")
def getTopTags(self,
artist = None,
track = None,
mbid = None):
params = self.__checkParams({'method': 'track.gettoptags'}, artist, track, mbid)
data = self.__api.fetchData(params).find('toptags')
topTags = property(getTopTags, None, None, "docstring")
topTag = property(lambda self: len(self.topTags) and self.topTags[0], None, None, "docstring")
@staticmethod
def search(api,
track,
artist = None,
limit = None,
page = None):
pass
from error import LastfmError
from user import user
from tag import Tag

111
lastfm/user.py Normal file
View File

@ -0,0 +1,111 @@
#!/usr/bin/env python
__author__ = "Abhinav Sarkar"
__version__ = "0.1"
__license__ = "GNU Lesser General Public License"
class User(object):
"""A class representing an user."""
def __init__(self,
api,
name = None,
url = None,
image = None):
self.__api = api
self.__name = name
self.__url = url
self.__image = image
def getName(self):
return self.__name
def getUrl(self):
return self.__url
def getImage(self):
return self.__image
name = property(getName, None, None, "Name's Docstring")
url = property(getUrl, None, None, "Url's Docstring")
image = property(getImage, None, None, "Image's Docstring")
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
weeklyTrackChart = property(getWeeklyTrackChart, None, None, "Docstring")

5
lastfm/weeklychart.py Normal file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env python
__author__ = "Abhinav Sarkar"
__version__ = "0.1"
__license__ = "GNU Lesser General Public License"