Implement geo.getTopTracks for #44

This commit is contained in:
hugovk 2014-03-04 16:14:52 +02:00
parent 2d11699df0
commit 9ca4109f22
2 changed files with 38 additions and 1 deletions

View file

@ -385,7 +385,6 @@ class _Network(object):
tag (Optional) : Specifies a tag to filter by. tag (Optional) : Specifies a tag to filter by.
festivalsonly[0|1] (Optional) : Whether only festivals should be returned, or all events. festivalsonly[0|1] (Optional) : Whether only festivals should be returned, or all events.
limit (Optional) : The number of results to fetch per page. Defaults to 10. limit (Optional) : The number of results to fetch per page. Defaults to 10.
(page number not implemented)
""" """
params = {} params = {}
@ -415,6 +414,34 @@ class _Network(object):
# geo.getMetroWeeklyChartlist # geo.getMetroWeeklyChartlist
# geo.getMetros # geo.getMetros
# geo.getTopArtists # geo.getTopArtists
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
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)
limit (Optional) : The number of results to fetch per page. Defaults to 50.
"""
params = {"country": country}
if location: params["location"] = location
if limit: params["limit"] = limit
doc = _Request(self, "geo.getTopTracks", params).execute(cacheable)
tracks = doc.getElementsByTagName("track")
seq = []
for track in tracks:
title = _extract(track, "name")
artist = _extract(track, "name", 1)
listeners = _extract(track, "listeners")
seq.append(TopItem(Track(artist, title, self), listeners))
return seq
# TODO?
# geo.getTopTracks # geo.getTopTracks
def enable_proxy(self, host, port): def enable_proxy(self, host, port):

View file

@ -896,6 +896,16 @@ 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_tracks(self):
# Arrange
# Act
tracks = self.network.get_geo_top_tracks(country = "United Kingdom", location = "Manchester", limit = 1)
# Assert
self.assertEqual(len(tracks), 1)
self.assertEqual(type(tracks[0]), pylast.TopItem)
if __name__ == '__main__': if __name__ == '__main__':
# For quick testing of a single case (eg. test = "test_scrobble") # For quick testing of a single case (eg. test = "test_scrobble")