* Fixed not using the limit on *.get_top_tags(limit). (Closes Issue #61)
This commit is contained in:
parent
96e90dfebf
commit
52ce81743a
23
pylast.py
23
pylast.py
|
@ -322,9 +322,11 @@ class _Network(object):
|
||||||
tag = Tag(_extract(node, "name"), self)
|
tag = Tag(_extract(node, "name"), self)
|
||||||
weight = _number(_extract(node, "count"))
|
weight = _number(_extract(node, "count"))
|
||||||
|
|
||||||
if len(seq) < limit:
|
|
||||||
seq.append(TopItem(tag, weight))
|
seq.append(TopItem(tag, weight))
|
||||||
|
|
||||||
|
if limit:
|
||||||
|
seq = seq[:limit]
|
||||||
|
|
||||||
return seq
|
return seq
|
||||||
|
|
||||||
def enable_proxy(self, host, port):
|
def enable_proxy(self, host, port):
|
||||||
|
@ -1075,7 +1077,7 @@ class _Taggable(object):
|
||||||
self.remove_tags(to_remove)
|
self.remove_tags(to_remove)
|
||||||
self.add_tags(to_add)
|
self.add_tags(to_add)
|
||||||
|
|
||||||
def get_top_tags(self, limit = None):
|
def get_top_tags(self, limit=None):
|
||||||
"""Returns a list of the most frequently used Tags on this object."""
|
"""Returns a list of the most frequently used Tags on this object."""
|
||||||
|
|
||||||
doc = self._request(self.ws_prefix + '.getTopTags', True)
|
doc = self._request(self.ws_prefix + '.getTopTags', True)
|
||||||
|
@ -1084,13 +1086,14 @@ class _Taggable(object):
|
||||||
seq = []
|
seq = []
|
||||||
|
|
||||||
for element in elements:
|
for element in elements:
|
||||||
if limit and len(seq) >= limit:
|
|
||||||
break
|
|
||||||
tag_name = _extract(element, 'name')
|
tag_name = _extract(element, 'name')
|
||||||
tagcount = _extract(element, 'count')
|
tagcount = _extract(element, 'count')
|
||||||
|
|
||||||
seq.append(TopItem(Tag(tag_name, self.network), tagcount))
|
seq.append(TopItem(Tag(tag_name, self.network), tagcount))
|
||||||
|
|
||||||
|
if limit:
|
||||||
|
seq = seq[:limit]
|
||||||
|
|
||||||
return seq
|
return seq
|
||||||
|
|
||||||
class WSError(Exception):
|
class WSError(Exception):
|
||||||
|
@ -1239,9 +1242,11 @@ class Album(_BaseObject, _Taggable):
|
||||||
|
|
||||||
seq = []
|
seq = []
|
||||||
for name in _extract_all(e, "name"):
|
for name in _extract_all(e, "name"):
|
||||||
if len(seq) < limit:
|
|
||||||
seq.append(Tag(name, self.network))
|
seq.append(Tag(name, self.network))
|
||||||
|
|
||||||
|
if limit:
|
||||||
|
seq = seq[:limit]
|
||||||
|
|
||||||
return seq
|
return seq
|
||||||
|
|
||||||
def get_tracks(self):
|
def get_tracks(self):
|
||||||
|
@ -3003,8 +3008,8 @@ class User(_BaseObject):
|
||||||
|
|
||||||
return seq
|
return seq
|
||||||
|
|
||||||
def get_top_tags(self, limit = None):
|
def get_top_tags(self, limit=None):
|
||||||
"""Returns a sequence of the top tags used by this user with their counts as (Tag, tagcount).
|
"""Returns a sequence of the top tags used by this user with their counts as TopItem objects.
|
||||||
* limit: The limit of how many tags to return.
|
* limit: The limit of how many tags to return.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -3012,9 +3017,11 @@ class User(_BaseObject):
|
||||||
|
|
||||||
seq = []
|
seq = []
|
||||||
for node in doc.getElementsByTagName("tag"):
|
for node in doc.getElementsByTagName("tag"):
|
||||||
if len(seq) < limit:
|
|
||||||
seq.append(TopItem(Tag(_extract(node, "name"), self.network), _extract(node, "count")))
|
seq.append(TopItem(Tag(_extract(node, "name"), self.network), _extract(node, "count")))
|
||||||
|
|
||||||
|
if limit:
|
||||||
|
seq = seq[:limit]
|
||||||
|
|
||||||
return seq
|
return seq
|
||||||
|
|
||||||
def get_top_tracks(self, period = PERIOD_OVERALL):
|
def get_top_tracks(self, period = PERIOD_OVERALL):
|
||||||
|
|
Loading…
Reference in a new issue