From 5518193bc248247a3ec0d1242c76b0eba099eb13 Mon Sep 17 00:00:00 2001 From: Abhinav Sarkar Date: Thu, 31 Jul 2008 10:34:46 +0000 Subject: [PATCH] changed property syntax from function call to decorator --- src/album.py | 65 +++++++++++----------- src/artist.py | 133 +++++++++++++++++++++++++-------------------- src/event.py | 72 ++++++++++++------------ src/geo.py | 107 +++++++++++++++++++----------------- src/group.py | 20 ++++--- src/playlist.py | 12 ++-- src/search.py | 46 ++++++++-------- src/stats.py | 60 ++++++++++---------- src/tag.py | 60 ++++++++++---------- src/tasteometer.py | 18 +++--- src/track.py | 81 ++++++++++++++++----------- src/user.py | 120 +++++++++++++++++++++++++++------------- 12 files changed, 447 insertions(+), 347 deletions(-) diff --git a/src/album.py b/src/album.py index 7809d3b..379137c 100644 --- a/src/album.py +++ b/src/album.py @@ -37,44 +37,62 @@ class Album(LastfmBase): rank = stats.rank ) self.__topTags = topTags - - def getName(self): + + @property + def name(self): + """name of the album""" return self.__name - def getArtist(self): + @property + def artist(self): + """artist of the album""" return self.__artist - - def getId(self): + + @property + def id(self): + """id of the album""" if self.__id is None: self._fillInfo() return self.__id - def getMbid(self): + @property + def mbid(self): + """mbid of the album""" if self.__mbid is None: self._fillInfo() return self.__mbid - def getUrl(self): + @property + def url(self): + """url of the album's page""" if self.__url is None: self._fillInfo() return self.__url - def getReleaseDate(self): + @property + def releaseDate(self): + """release date of the album""" if self.__releaseDate is None: self._fillInfo() return self.__releaseDate - def getImage(self): + @property + def image(self): + """cover images of the album""" if self.__image is None: self._fillInfo() return self.__image - def getStats(self): + @property + def stats(self): + """stats related to the album""" if self.__stats is None: self._fillInfo() return self.__stats - def getTopTags(self): + @property + def topTags(self): + """top tags for the album""" if self.__topTags is None: params = {'method': 'album.getinfo'} if self.artist and self.name: @@ -92,25 +110,10 @@ class Album(LastfmBase): ] return self.__topTags - name = property(getName, None, None, "Name's Docstring") - - artist = property(getArtist, None, None, "Artist's Docstring") - - id = property(getId, None, None, "Id's Docstring") - - mbid = property(getMbid, None, None, "Mbid's Docstring") - - url = property(getUrl, None, None, "Url's Docstring") - - releaseDate = property(getReleaseDate, None, None, "ReleaseDate's Docstring") - - image = property(getImage, None, None, "Image's Docstring") - - stats = property(getStats, None, None, "Stats's Docstring") - - topTags = property(getTopTags, None, None, "TopTags's Docstring") - topTag = property(lambda self: self.topTags and len(self.topTags) and self.topTags[0], - None, None, "docstring") + @property + def topTag(self): + """top tag for the album""" + return (self.topTags and len(self.topTags) and self.topTags[0] or None) @staticmethod def _fetchData(api, @@ -135,7 +138,7 @@ class Album(LastfmBase): datetime(*(time.strptime(data.findtext('releasedate').strip(), '%d %b %Y, 00:00')[0:6])) self.__image = dict([(i.get('size'), i.text) for i in data.findall('image')]) self.__stats = Stats( - subject = data.findtext('name'), + subject = self, listeners = int(data.findtext('listeners')), playcount = int(data.findtext('playcount')), ) diff --git a/src/artist.py b/src/artist.py index 675c435..955cf53 100644 --- a/src/artist.py +++ b/src/artist.py @@ -47,30 +47,42 @@ class Artist(LastfmBase): self.__topTracks = None self.__topFans = None - def getName(self): + @property + def name(self): + """name of the artist""" return self.__name - def getMbid(self): + @property + def mbid(self): + """mbid of the artist""" if self.__mbid is None: self._fillInfo() return self.__mbid - def getUrl(self): + @property + def url(self): + """url of the artist's page""" if self.__url is None: self._fillInfo() return self.__url - def getImage(self): + @property + def image(self): + """images of the artist""" if self.__image is None: self._fillInfo() return self.__image - def isStreamable(self): + @property + def streamable(self): + """is the artist streamable""" if self.__streamable is None: self._fillInfo() return self.__streamable - def getStats(self): + @property + def stats(self): + """stats for the artist""" if self.__stats is None: self._fillInfo() return self.__stats @@ -99,7 +111,19 @@ class Artist(LastfmBase): ] return self.__similar - def getTopTags(self): + @property + def similar(self): + """artists similar to this artist""" + return self.getSimilar() + + @property + def mostSimilar(self): + """artist most similar to this artist""" + return (len(self.similar) and self.similar[0] or None) + + @property + def topTags(self): + """top tags for the artist""" if self.__topTags is None or len(self.__topTags) < 6: params = { 'method': 'artist.gettoptags', @@ -115,35 +139,22 @@ class Artist(LastfmBase): for t in data.findall('tag') ] return self.__topTags + + @property + def topTag(self): + """top tag for the artist""" + return (len(self.topTags) and self.topTags[0] or None) - def getBio(self): + @property + def bio(self): + """biography of the artist""" if self.__bio is None: self._fillInfo() return self.__bio - - name = property(getName, None, None, "Name's Docstring") - - mbid = property(getMbid, None, None, "Mbid's Docstring") - url = property(getUrl, None, None, "Url's Docstring") - - image = property(getImage, None, None, "Image's Docstring") - - streamable = property(isStreamable, None, None, "Streamable's Docstring") - - stats = property(getStats, None, None, "Stats's Docstring") - - similar = property(getSimilar, None, None, "Similar's Docstring") - mostSimilar = property(lambda self: len(self.similar) and self.similar[0], - None, None, "docstring") - - topTags = property(getTopTags, None, None, "Tags's Docstring") - topTag = property(lambda self: len(self.topTags) and self.topTags[0], - None, None, "docstring") - - bio = property(getBio, None, None, "Bio's Docstring") - - def getEvents(self): + @property + def events(self): + """events for the artist""" if self.__events is None: params = {'method': 'artist.getevents', 'artist': self.name} data = self.__api._fetchData(params).find('events') @@ -188,11 +199,11 @@ class Artist(LastfmBase): ) for e in data.findall('event') ] - return self.__events + return self.__events - events = property(getEvents, None, None, "Docstring") - - def getTopAlbums(self): + @property + def topAlbums(self): + """top albums of the artist""" if self.__topAlbums is None: params = {'method': 'artist.gettopalbums', 'artist': self.name} data = self.__api._fetchData(params).find('topalbums') @@ -215,11 +226,14 @@ class Artist(LastfmBase): ] return self.__topAlbums - topAlbums = property(getTopAlbums, None, None, "Docstring") - topAlbum = property(lambda self: len(self.topAlbums) and self.topAlbums[0], - None, None, "docstring") + @property + def topAlbum(self): + """top album of the artist""" + return (len(self.topAlbums) and self.topAlbums[0] or None) - def getTopFans(self): + @property + def topFans(self): + """top fans of the artist""" if self.__topFans is None: params = {'method': 'artist.gettopfans', 'artist': self.name} data = self.__api._fetchData(params).find('topfans') @@ -238,11 +252,14 @@ class Artist(LastfmBase): ] return self.__topFans - topFans = property(getTopFans, None, None, "Docstring") - topFan = property(lambda self: len(self.topFans) and self.topFans[0], - None, None, "docstring") + @property + def topFan(self): + """top fan of the artist""" + return (len(self.topFans) and self.topFans[0] or None) - def getTopTracks(self): + @property + def topTracks(self): + """top tracks of the artist""" if self.__topTracks is None: params = {'method': 'artist.gettoptracks', 'artist': self.name} data = self.__api._fetchData(params).find('toptracks') @@ -265,9 +282,9 @@ class Artist(LastfmBase): ] return self.__topTracks - topTracks = property(getTopTracks, None, None, "Docstring") - topTrack = property(lambda self: len(self.topTracks) and self.topTracks[0], - None, None, "docstring") + @property + def topTrack(self): + return (len(self.topTracks) and self.topTracks[0] or None) @staticmethod def search(api, @@ -402,26 +419,26 @@ class Bio(object): self.__summary = summary self.__content = content - def getArtist(self): + @property + def artist(self): + """artist for which the biography is""" return self.__artist - def getPublished(self): + @property + def published(self): + """publication time of the biography""" return self.__published - def getSummary(self): + @property + def summary(self): + """summary of the biography""" return self.__summary - def getContent(self): + @property + def content(self): + """content of the biography""" return self.__content - published = property(getPublished, None, None, "Published's Docstring") - - summary = property(getSummary, None, None, "Summary's Docstring") - - content = property(getContent, None, None, "Content's Docstring") - - artist = property(getArtist, None, None, "Artist's Docstring") - def __repr__(self): return "" % self.__artist.name diff --git a/src/event.py b/src/event.py index d04d964..14bb170 100644 --- a/src/event.py +++ b/src/event.py @@ -42,65 +42,65 @@ class Event(LastfmBase): ) self.__tag = tag - def getId(self): + @property + def id(self): + """id of the event""" return self.__id - def getTitle(self): + @property + def title(self): + """title of the event""" return self.__title - def getArtists(self): + @property + def artists(self): + """artists performing in the event""" return self.__artists - def getHeadliner(self): + @property + def headliner(self): + """headliner artist of the event""" return self.__headliner - def getVenue(self): + @property + def venue(self): + """venue of the event""" return self.__venue - def getStartDate(self): + @property + def startDate(self): + """start date of the event""" return self.__startDate - def getStartTime(self): + @property + def startTime(self): + """start time of the event""" return self.__startTime - def getDescription(self): + @property + def description(self): + """description of the event""" return self.__description - def getImage(self): + @property + def image(self): + """poster of the event""" return self.__image - def getUrl(self): + @property + def url(self): + """url of the event's page""" return self.__url - def getStats(self): + @property + def stats(self): + """stats of the event""" return self.__stats - def getTag(self): + @property + def tag(self): + """tags for the event""" return self.__tag - - id = property(getId, None, None, "Id's Docstring") - - title = property(getTitle, None, None, "Title's Docstring") - - artists = property(getArtists, None, None, "Artists's Docstring") - - headliner = property(getHeadliner, None, None, "headliner's Docstring") - - venue = property(getVenue, None, None, "Venue's Docstring") - - startDate = property(getStartDate, None, None, "StartDate's Docstring") - - startTime = property(getStartTime, None, None, "StartTime's Docstring") - - description = property(getDescription, None, None, "Description's Docstring") - - image = property(getImage, None, None, "Image's Docstring") - - url = property(getUrl, None, None, "Url's Docstring") - - stats = property(getStats, None, None, "Match's Docstring") - - tag = property(getTag, None, None, "Tag's Docstring") @staticmethod def getInfo(api, event): diff --git a/src/geo.py b/src/geo.py index fe82aec..55dfd7f 100644 --- a/src/geo.py +++ b/src/geo.py @@ -122,21 +122,21 @@ class Venue(LastfmBase): self.__location = location self.__url = url - def getName(self): + @property + def name(self): + """name of the venue""" return self.__name - def getLocation(self): + @property + def location(self): + """location of the event""" return self.__location - def getUrl(self): + @property + def url(self): + """url of the event's page""" return self.__url - - name = property(getName, None, None, "Name's Docstring") - - location = property(getLocation, None, None, "Location's Docstring") - - url = property(getUrl, None, None, "Url's Docstring") - + @staticmethod def hashFunc(*args, **kwds): try: @@ -181,53 +181,56 @@ class Location(LastfmBase): self.__latitude = latitude self.__longitude = longitude self.__timezone = timezone - - def getName(self): + + @property + def name(self): + """name of the location""" return self.__name - def getCity(self): + @property + def city(self): + """city in which the location is situated""" return self.__city - def getCountry(self): + @property + def country(self): + """country in which the location is situated""" return self.__country - def getStreet(self): + @property + def street(self): + """street in which the location is situated""" return self.__street - def getPostalCode(self): + @property + def postalCode(self): + """postal code of the location""" return self.__postalCode - def getLatitude(self): + @property + def latitude(self): + """latitude of the location""" return self.__latitude - def getLongitude(self): + @property + def longitude(self): + """longitude of the location""" return self.__longitude - def getTimezone(self): + @property + def timezone(self): + """timezone in which the location is situated""" return self.__timezone - - name = property(getName, None, None, "Name's Docstring") - - city = property(getCity, None, None, "City's Docstring") - - country = property(getCountry, None, None, "Country's Docstring") - - street = property(getStreet, None, None, "Street's Docstring") - - postalCode = property(getPostalCode, None, None, "PostalCode's Docstring") - - latitude = property(getLatitude, None, None, "Latitude's Docstring") - - longitude = property(getLongitude, None, None, "Longitude's Docstring") - - timezone = property(getTimezone, None, None, "Timezone's Docstring") - + def getEvents(self, distance = None, page = None): return Geo.getEvents(self.__api, self.name, distance, page).matches - events = property(getEvents, None, None, "Event's Docstring") + @property + def events(self): + """events taking place at/around the location""" + return self.getEvents() @staticmethod def hashFunc(*args, **kwds): @@ -272,26 +275,30 @@ class Country(LastfmBase): self.__api = api self.__name = name - def getName(self): + @property + def name(self): + """name of the country""" return self.__name - name = property(getName, None, None, "Name's Docstring") - - def getTopArtists(self): + @property + def topArtists(self): + """top artists of the country""" return Geo.getTopArtists(self.__api, self.name) - topArtists = property(getTopArtists, None, None, "Docstring") - topArtist = property( - lambda self: len(self.topArtists) and self.topArtists[0] or None, - None, None, "Docstring" - ) + @property + def topArtist(self): + """top artist of the country""" + return (len(self.topArtists) and self.topArtists[0] or None) - def getTopTracks(self): + @property + def topTracks(self): + """top tracks of the country""" return Geo.getTopTracks(self.__api, self.name) - topTracks = property(getTopTracks, None, None, "Docstring") - topTrack = property(lambda self: len(self.topTracks) and self.topTracks[0] or None, - None, None, "Docstring") + @property + def topTrack(self): + """top track of the country""" + return (len(self.topTracks) and self.topTracks[0] or None) @staticmethod def hashFunc(*args, **kwds): diff --git a/src/group.py b/src/group.py index 45ed78b..2234ceb 100644 --- a/src/group.py +++ b/src/group.py @@ -16,12 +16,12 @@ class Group(LastfmBase): self.__api = api self.__name = name - def getName(self): + @property + def name(self): return self.__name - name = property(getName, None, None, "Name's Docstring") - - def getWeeklyChartList(self): + @property + def weeklyChartList(self): pass def getWeeklyAlbumChart(self, @@ -29,21 +29,27 @@ class Group(LastfmBase): end = None): pass - weeklyAlbumChart = property(getWeeklyAlbumChart, None, None, "Docstring") + @property + def recentWeeklyAlbumChart(self): + return self.getWeeklyAlbumChart() def getWeeklyArtistChart(self, start = None, end = None): pass - weeklyArtistChart = property(getWeeklyArtistChart, None, None, "Docstring") + @property + def recentWeeklyArtistChart(self): + return self.getWeeklyArtistChart() def getWeeklyTrackChart(self, start = None, end = None): pass - weeklyTrackChart = property(getWeeklyTrackChart, None, None, "Docstring") + @property + def recentWeeklyTrackChart(self): + return self.getWeeklyTrackChart() @staticmethod def hashFunc(*args, **kwds): diff --git a/src/playlist.py b/src/playlist.py index 21d24ad..2aaa218 100644 --- a/src/playlist.py +++ b/src/playlist.py @@ -12,16 +12,16 @@ class Playlist(LastfmBase): self.__data = xpsfData self.__url = url - def getData(self): + @property + def data(self): + """playlist's data""" return self.__data - def getUrl(self): + @property + def url(self): + """url of the playlist""" return self.__url - data = property(getData, None, None, "docstring") - - url = property(getUrl, None, None, "url's Docstring") - @staticmethod def fetch(api, url): params = {'method': 'playlist.fetch', 'playlistURL': url} diff --git a/src/search.py b/src/search.py index 47c28ca..fea9d7e 100644 --- a/src/search.py +++ b/src/search.py @@ -25,42 +25,44 @@ class SearchResult(LastfmBase): self.__itemsPerPage = itemsPerPage self.__matches = matches - def getType(self): + @property + def type(self): + """type of the search""" return self.__type - def getSearchTerms(self): + @property + def searchTerms(self): + """terms searched for in the search""" return self.__searchTerms - def getStartPage(self): + @property + def startPage(self): + """start page of the search""" return self.__startPage - def getTotalResults(self): + @property + def totalResults(self): + """number of total results for the search""" return self.__totalResults - def getStartIndex(self): + @property + def startIndex(self): + """start index of the search""" return self.__startIndex - def getItemsPerPage(self): + @property + def itemsPerPage(self): + """number of items per page for the search""" return self.__itemsPerPage - def getMatches(self): + @property + def matches(self): + """match result of the search""" return self.__matches - type = property(getType, None, None, "Type's Docstring") - - searchTerms = property(getSearchTerms, None, None, "SearchTerm's Docstring") - - startPage = property(getStartPage, None, None, "StartPage's Docstring") - - totalResults = property(getTotalResults, None, None, "TotalResults's Docstring") - - startIndex = property(getStartIndex, None, None, "StartIndex's Docstring") - - itemsPerPage = property(getItemsPerPage, None, None, "ItemsPerPage's Docstring") - - matches = property(getMatches, None, None, "Matches's Docstring") - topMatch = property(lambda self: len(self.matches) and self.matches[0], - None, None, "docstring") + @property + def topMatch(self): + return (len(self.matches) and self.matches[0] or None) @staticmethod def hashFunc(*args, **kwds): diff --git a/src/stats.py b/src/stats.py index 6c3b843..e79d74c 100644 --- a/src/stats.py +++ b/src/stats.py @@ -28,56 +28,56 @@ class Stats(object): self.__attendance = attendance self.__reviews = reviews - def getSubject(self): + @property + def subject(self): + """subject of the stats""" return self.__subject - def getRank(self): + @property + def rank(self): + """rank of the subject""" return self.__rank - def getListeners(self): + @property + def listeners(self): + """number of listeners of the subject""" return self.__listeners - def getPlaycount(self): + @property + def playcount(self): + """playcount of the subject""" return self.__playcount - def getTagcount(self): + @property + def tagcount(self): + """tagcount of the subject""" return self.__tagcount - def getCount(self): + @property + def count(self): + """count of the subject""" return self.__count - def getMatch(self): + @property + def match(self): + """match of the subject""" return self.__match - def getWeight(self): + @property + def weight(self): + """weight of the subject""" return self.__weight - def getAttendance(self): + @property + def attendance(self): + """attendance of the subject""" return self.__attendance - def getReviews(self): + @property + def reviews(self): + """reviews of the subject""" return self.__reviews - listeners = property(getListeners, None, None, "Listeners's Docstring") - - playcount = property(getPlaycount, None, None, "Plays's Docstring") - - tagcount = property(getTagcount, None, None, "Plays's Docstring") - - count = property(getCount, None, None, "Plays's Docstring") - - match = property(getMatch, None, None, "Match's Docstring") - - rank = property(getRank, None, None, "Artist's Docstring") - - subject = property(getSubject, None, None, "subject's Docstring") - - weight = property(getWeight, None, None, "Weight's Docstring") - - attendance = property(getAttendance, None, None, "Attendance's Docstring") - - reviews = property(getReviews, None, None, "Reviews's Docstring") - def __repr__(self): return "" % self.__subject.name \ No newline at end of file diff --git a/src/tag.py b/src/tag.py index 236a316..e270d06 100644 --- a/src/tag.py +++ b/src/tag.py @@ -24,22 +24,24 @@ class Tag(LastfmBase): self.__topArtists = None self.__topTracks = None - def getName(self): + @property + def name(self): + """name of the tag""" return self.__name - def getUrl(self): + @property + def url(self): + """url of the tag's page""" return self.__url - def isStreamable(self): + @property + def streamable(self): + """is the tag streamable""" return self.__streamable - name = property(getName, None, None, "Name's Docstring") - - url = property(getUrl, None, None, "Url's Docstring") - - streamable = property(isStreamable, None, None, "Docstring") - - def getSimilar(self): + @property + def similar(self): + """tags similar to this tag""" if self.__similar is None: params = {'method': 'tag.getsimilar', 'tag': self.name} data = self.__api._fetchData(params).find('similartags') @@ -54,9 +56,9 @@ class Tag(LastfmBase): ] return self.__similar - similar = property(getSimilar, None, None, "Docstring") - - def getTopAlbums(self): + @property + def topAlbums(self): + """top albums for the tag""" if self.__topAlbums is None: params = {'method': 'tag.gettopalbums', 'tag': self.name} data = self.__api._fetchData(params).find('topalbums') @@ -83,13 +85,14 @@ class Tag(LastfmBase): ] return self.__topAlbums - topAlbums = property(getTopAlbums, None, None, "Docstring") - topAlbum = property( - lambda self: len(self.topAlbums) and self.topAlbums[0] or None, - None, None, "Docstring" - ) + @property + def topAlbum(self): + """top album for the tag""" + return (len(self.topAlbums) and self.topAlbums[0] or None) - def getTopArtists(self): + @property + def topArtists(self): + """top artists for the tag""" if self.__topArtists is None: params = {'method': 'tag.gettopartists', 'tag': self.name} data = self.__api._fetchData(params).find('topartists') @@ -111,13 +114,14 @@ class Tag(LastfmBase): ] return self.__topArtists - topArtists = property(getTopArtists, None, None, "Docstring") - topArtist = property( - lambda self: len(self.topArtists) and self.topArtists[0] or None, - None, None, "Docstring" - ) + @property + def topArtist(self): + """top artist for the tag""" + return (len(self.topArtists) and self.topArtists[0] or None) - def getTopTracks(self): + @property + def topTracks(self): + """top tracks for the tag""" if self.__topTracks is None: params = {'method': 'tag.gettoptracks', 'tag': self.name} data = self.__api._fetchData(params).find('toptracks') @@ -145,9 +149,9 @@ class Tag(LastfmBase): ] return self.__topTracks - topTracks = property(getTopTracks, None, None, "Docstring") - topTrack = property(lambda self: len(self.topTracks) and self.topTracks[0], - None, None, "docstring") + @property + def topTrack(self): + return (len(self.topTracks) and self.topTracks[0] or None) @staticmethod def getTopTags(api): diff --git a/src/tasteometer.py b/src/tasteometer.py index 2c961c7..f3d3fe5 100644 --- a/src/tasteometer.py +++ b/src/tasteometer.py @@ -14,20 +14,20 @@ class Tasteometer(object): self.__matches = matches self.__artists = artists#set - def getScore(self): + @property + def score(self): + """score of the comparison""" return self.__score - def getMatches(self): + @property + def matches(self): + """matches for the comparison""" return self.__matches - def getArtists(self): + @property + def artists(self): + """artists for the comparison""" return self.__artists - - score = property(getScore, None, None, "Score's Docstring") - - matches = property(getMatches, None, None, "Matches's Docstring") - - artists = property(getArtists, None, None, "Artists's Docstring") @staticmethod def compare(api, diff --git a/src/track.py b/src/track.py index 2547f19..08823b1 100644 --- a/src/track.py +++ b/src/track.py @@ -35,45 +35,45 @@ class Track(LastfmBase): ) self.__fullTrack = fullTrack - def getName(self): + @property + def name(self): + """name of the track""" return self.__name - def getMbid(self): + @property + def mbid(self): + """mbid of the track""" return self.__mbid - def getUrl(self): + @property + def url(self): + """url of the tracks's page""" return self.__url - def isStreamable(self): + @property + def streamable(self): + """is the track streamable""" return self.__streamable - def getArtist(self): + @property + def artist(self): + """artist of the track""" return self.__artist - def getImage(self): + @property + def image(self): + """image of the track's album cover""" return self.__image - def getStats(self): + @property + def stats(self): + """stats of the track""" return self.__stats - def getFullTrack(self): + @property + def fullTrack(self): + """is the full track streamable""" return self.__fullTrack - - name = property(getName, None, None, "Name's Docstring") - - mbid = property(getMbid, None, None, "Mbid's Docstring") - - url = property(getUrl, None, None, "Url's Docstring") - - streamable = property(isStreamable, None, None, "Streamable's Docstring") - - artist = property(getArtist, None, None, "Artist's Docstring") - - image = property(getImage, None, None, "Image's Docstring") - - stats = property(getStats, None, None, "Match's Docstring") - - fullTrack = property(getFullTrack, None, None, "Match's Docstring") def __checkParams(self, params, @@ -96,9 +96,15 @@ class Track(LastfmBase): 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") + @property + def similar(self): + """tracks similar to this track""" + return self.getSimilar() + + @property + def mostSimilar(self): + """track most similar to this track""" + return (len(self.similar) and self.similar[0] or None) def getTopFans(self, artist = None, @@ -107,9 +113,14 @@ class Track(LastfmBase): 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") + @property + def topFans(self): + """top fans of the track""" + return self.getTopFans() + + @property + def topFan(self): + return (len(self.topFans) and self.topFans[0] or None) def getTopTags(self, artist = None, @@ -118,8 +129,14 @@ class Track(LastfmBase): 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") + @property + def topTags(self): + """top tags for the track""" + return self.getTopTags() + + @property + def topTag(self): + return (len(self.topTags) and self.topTags[0] or None) @staticmethod def search(api, diff --git a/src/user.py b/src/user.py index d68617e..a12ba97 100644 --- a/src/user.py +++ b/src/user.py @@ -26,82 +26,120 @@ class User(LastfmBase): weight = stats.weight ) - def getName(self): + @property + def name(self): + """name of the user""" return self.__name - def getUrl(self): + @property + def url(self): + """url of the user's page""" return self.__url - def getImage(self): + @property + def image(self): + """image of the user""" return self.__image - def getStats(self): + @property + def stats(self): + """stats for the user""" return self.__stats - - 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") - - def getEvents(self): + + @property + def events(self): pass - events = property(getEvents, None, None, "docstring") - def getFriends(self, recentTracks = False, limit = None): pass - friends = property(getFriends, None, None, "docstring") + @property + def friends(self): + """friends of the user""" + return self.getFriends() def getNeighbours(self, limit = None): pass - neighbours = property(getNeighbours, None, None, "docstring") + @property + def neighbours(self): + """neightbours of the user""" + return self.getNeighbours() - def getPlaylists(self): + @property + def playlists(self): + """playlists of the user""" pass - playlists = property(getPlaylists, None, None, "docstring") - def getRecentTracks(self, limit = None): pass - recentTracks = property(getRecentTracks, None, None, "docstring") + @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) 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") + @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) 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") + @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) 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") + @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) 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") + @property + def topTags(self): + """top tags of the user""" + return self.getTopTags() - def getWeeklyChartList(self): + @property + def topTag(self): + """top tag of the user""" + return (len(self.topTags) and self.topTags[0] or None) + + @property + def weeklyChartList(self): pass def getWeeklyAlbumChart(self, @@ -109,21 +147,27 @@ class User(LastfmBase): end = None): pass - weeklyAlbumChart = property(getWeeklyAlbumChart, None, None, "Docstring") + @property + def recentWeeklyAlbumChart(self): + return self.getWeeklyAlbumChart() def getWeeklyArtistChart(self, start = None, end = None): pass - weeklyArtistChart = property(getWeeklyArtistChart, None, None, "Docstring") + @property + def recentWeeklyArtistChart(self): + return self.getWeeklyArtistChart() def getWeeklyTrackChart(self, start = None, end = None): pass - weeklyTrackChart = property(getWeeklyTrackChart, None, None, "Docstring") + @property + def recentWeeklyTrackChart(self): + return self.getWeeklyTrackChart() @staticmethod def hashFunc(*args, **kwds):