diff --git a/pylast.py b/pylast.py index 4a7bd29..02ea3c1 100644 --- a/pylast.py +++ b/pylast.py @@ -415,8 +415,31 @@ class _Network(object): # geo.getMetros # geo.getTopArtists + def get_geo_top_artists(self, country, limit=None, cacheable=True): + """Get the most popular artists on Last.fm by country. + Parameters: + country (Required) : A country name, as defined by the ISO 3166-1 country names standard + limit (Optional) : The number of results to fetch per page. Defaults to 50. + """ + params = {"country": country} + + if limit: params["limit"] = limit + + doc = _Request(self, "geo.getTopArtists", params).execute(cacheable) + + artists = doc.getElementsByTagName("artist") + seq = [] + + for artist in artists: + name = _extract(artist, "name") + listeners = _extract(artist, "listeners") + + seq.append(TopItem(Artist(name, self), listeners)) + + return seq + def get_geo_top_tracks(self, country, location=None, limit=None, cacheable=True): - """Get the most popular tracks on Last.fm last week by country + """Get the most popular tracks on Last.fm last week by country. Parameters: country (Required) : A country name, as defined by the ISO 3166-1 country names standard location (Optional) : A metro name, to fetch the charts for (must be within the country specified) diff --git a/test_pylast.py b/test_pylast.py index 2f3318e..e8d84dd 100755 --- a/test_pylast.py +++ b/test_pylast.py @@ -896,6 +896,17 @@ class TestPyLast(unittest.TestCase): self.assertEqual(event.get_venue().location['city'], "Reading") + def test_geo_get_top_artists(self): + # Arrange + # Act + artists = self.network.get_geo_top_artists(country = "United Kingdom", limit = 1) + + # Assert + self.assertEqual(len(artists), 1) + self.assertEqual(type(artists[0]), pylast.TopItem) + self.assertEqual(type(artists[0].item), pylast.Artist) + + def test_geo_get_top_tracks(self): # Arrange # Act @@ -904,6 +915,7 @@ class TestPyLast(unittest.TestCase): # Assert self.assertEqual(len(tracks), 1) self.assertEqual(type(tracks[0]), pylast.TopItem) + self.assertEqual(type(tracks[0].item), pylast.Track) if __name__ == '__main__':