Implement geo.getTopArtists for #44
This commit is contained in:
parent
9ca4109f22
commit
748f66ecc3
25
pylast.py
25
pylast.py
|
@ -415,8 +415,31 @@ class _Network(object):
|
||||||
# geo.getMetros
|
# geo.getMetros
|
||||||
# geo.getTopArtists
|
# 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):
|
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:
|
Parameters:
|
||||||
country (Required) : A country name, as defined by the ISO 3166-1 country names standard
|
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)
|
location (Optional) : A metro name, to fetch the charts for (must be within the country specified)
|
||||||
|
|
|
@ -896,6 +896,17 @@ class TestPyLast(unittest.TestCase):
|
||||||
self.assertEqual(event.get_venue().location['city'], "Reading")
|
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):
|
def test_geo_get_top_tracks(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Act
|
# Act
|
||||||
|
@ -904,6 +915,7 @@ class TestPyLast(unittest.TestCase):
|
||||||
# Assert
|
# Assert
|
||||||
self.assertEqual(len(tracks), 1)
|
self.assertEqual(len(tracks), 1)
|
||||||
self.assertEqual(type(tracks[0]), pylast.TopItem)
|
self.assertEqual(type(tracks[0]), pylast.TopItem)
|
||||||
|
self.assertEqual(type(tracks[0].item), pylast.Track)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue