From 960a3cb2efaa4642cb897398a643b58b1d9d0a19 Mon Sep 17 00:00:00 2001 From: skillachie Date: Sat, 11 Apr 2015 16:46:44 -0400 Subject: [PATCH 1/4] adding support for tag.getTopTracks http://www.last.fm/api/show/tag.getTopTracks --- pylast/__init__.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index c0d700b..3360205 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -405,7 +405,33 @@ class _Network(object): return seq - def get_geo_events( + def get_top_tracks_by_tag(self, tag, limit=None, cacheable=True): + """Returns the top tracks by tag as a sequence of TopItem objects. + Parameters: + tag (Required) : A country name, as defined by the ISO 3166-1 + limit (Optional) : The number of results to fetch per page.Defaults to 50. + """ + + params = {"tag":tag} + + if limit: + params["limit"] = limit + + doc = _Request(self,"tag.getTopTracks",params).execute(cacheable) + seq = [] + + for node in doc.getElementsByTagName("track"): + title = _extract(node,"name") + artist = _extract(node,"name",1) + track = Track(artist,title,self) + weight = _number(_extract(node, "playcount")) + + seq.append(TopItem(track,weight)) + + return seq + + + get_geo_events( self, longitude=None, latitude=None, location=None, distance=None, tag=None, festivalsonly=None, limit=None, cacheable=True): """ @@ -420,6 +446,7 @@ class _Network(object): distance (Optional) : Find events within a specified radius (in kilometres) tag (Optional) : Specifies a tag to filter by. + pTracks festivalsonly[0|1] (Optional) : Whether only festivals should be returned, or all events. limit (Optional) : The number of results to fetch per page. From fde15d90e2899c6c42ea59f138bc058eaa771fee Mon Sep 17 00:00:00 2001 From: skillachie Date: Sat, 11 Apr 2015 16:49:02 -0400 Subject: [PATCH 2/4] whoopsy --- pylast/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index 3360205..6058130 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -431,7 +431,7 @@ class _Network(object): return seq - get_geo_events( + def get_geo_events( self, longitude=None, latitude=None, location=None, distance=None, tag=None, festivalsonly=None, limit=None, cacheable=True): """ From e6d74a700347a3f3f5e3c0a1a04833a4d78fb80f Mon Sep 17 00:00:00 2001 From: skillachie Date: Sat, 11 Apr 2015 23:30:37 -0400 Subject: [PATCH 3/4] added test --- tests/test_pylast.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_pylast.py b/tests/test_pylast.py index 37695bf..b7fec8b 100755 --- a/tests/test_pylast.py +++ b/tests/test_pylast.py @@ -983,6 +983,17 @@ class TestPyLast(unittest.TestCase): self.assertIsInstance(tracks[0], pylast.TopItem) self.assertIsInstance(tracks[0].item, pylast.Track) + def test_tag_get_top_tracks(self): + # Arrange + # Act + tags = self.network.get_top_tracks_by_tag( + tag="happy", limit=1) + + # Assert + self.assertEqual(len(tags), 1) + self.assertIsInstance(tags[0], pylast.TopItem) + self.assertIsInstance(tags[0].item, pylast.Track) + def test_metro_class(self): # Arrange # Act From 9f29a437f0b98f2a289d4f1b0d1f8c89fb9280eb Mon Sep 17 00:00:00 2001 From: skillachie Date: Sat, 11 Apr 2015 23:36:19 -0400 Subject: [PATCH 4/4] fix --- pylast/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index 6058130..098bffb 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -446,7 +446,6 @@ class _Network(object): distance (Optional) : Find events within a specified radius (in kilometres) tag (Optional) : Specifies a tag to filter by. - pTracks festivalsonly[0|1] (Optional) : Whether only festivals should be returned, or all events. limit (Optional) : The number of results to fetch per page.