Implement geo.getMetroWeeklyChartlist and geo.getMetroArtistChart for #44
This commit is contained in:
parent
f7e5645ed6
commit
a254a9fd0c
55
pylast.py
55
pylast.py
|
@ -411,14 +411,17 @@ class _Network(object):
|
|||
|
||||
return _extract_events_from_doc(doc, self)
|
||||
|
||||
# TODO?
|
||||
# geo.getMetroArtistChart
|
||||
# geo.getMetroHypeArtistChart
|
||||
# geo.getMetroHypeTrackChart
|
||||
# geo.getMetroTrackChart
|
||||
# geo.getMetroUniqueArtistChart
|
||||
# geo.getMetroUniqueTrackChart
|
||||
# geo.getMetroWeeklyChartlist
|
||||
def get_metro_weekly_chart_dates(self, cacheable=True):
|
||||
"""Returns a list of From and To tuples for the available metro charts."""
|
||||
|
||||
doc = _Request(self, "geo.getMetroWeeklyChartlist").execute(cacheable)
|
||||
|
||||
seq = []
|
||||
for node in doc.getElementsByTagName("chart"):
|
||||
seq.append( (node.getAttribute("from"), node.getAttribute("to")) )
|
||||
|
||||
return seq
|
||||
|
||||
def get_metros(self, country=None, cacheable=True):
|
||||
"""Get a list of valid countries and metros for use in the other webservices.
|
||||
Parameters:
|
||||
|
@ -2143,7 +2146,7 @@ class Metro(_BaseObject):
|
|||
self.get_country().lower() != other.get_country().lower()
|
||||
|
||||
def _get_params(self):
|
||||
return {'name': self.get_name(), 'country': self.get_country()}
|
||||
return {'metro': self.get_name(), 'country': self.get_country()}
|
||||
|
||||
def get_name(self):
|
||||
"""Returns the metro name."""
|
||||
|
@ -2155,6 +2158,40 @@ class Metro(_BaseObject):
|
|||
|
||||
return self.country
|
||||
|
||||
def get_artist_chart(self, limit=None, cacheable=True):
|
||||
"""Get a chart of artists for a metro.
|
||||
Parameters:
|
||||
TODO start (Optional) : Beginning timestamp of the weekly range requested (c.f. geo.getWeeklyChartlist)
|
||||
TODO end (Optional) : Ending timestamp of the weekly range requested (c.f. geo.getWeeklyChartlist)
|
||||
limit (Optional) : The number of results to fetch per page. Defaults to 50.
|
||||
"""
|
||||
|
||||
params = self._get_params()
|
||||
if limit: params["limit"] = limit
|
||||
# if from_date and to_date:
|
||||
# params["from"] = from_date
|
||||
# params["to"] = to_date
|
||||
|
||||
doc = self._request("geo.getMetroArtistChart", cacheable, params)
|
||||
|
||||
seq = []
|
||||
for node in doc.getElementsByTagName("artist"):
|
||||
item = Artist(_extract(node, "name"), self.network)
|
||||
weight = _number(_extract(node, "listeners"))
|
||||
seq.append(TopItem(item, weight))
|
||||
|
||||
return seq
|
||||
|
||||
|
||||
# TODO?
|
||||
# geo.getMetroHypeArtistChart
|
||||
# geo.getMetroHypeTrackChart
|
||||
# geo.getMetroTrackChart
|
||||
# geo.getMetroUniqueArtistChart
|
||||
# geo.getMetroUniqueTrackChart
|
||||
# geo.getMetroWeeklyChartlist
|
||||
|
||||
|
||||
class Library(_BaseObject):
|
||||
"""A user's Last.fm library."""
|
||||
|
||||
|
|
|
@ -904,6 +904,28 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertEqual(event.get_venue().location['city'], "Reading")
|
||||
|
||||
|
||||
def test_get_metro_artist_chart(self):
|
||||
# Arrange
|
||||
metro = self.network.get_metro("Salamanca", "Spain")
|
||||
|
||||
# Act
|
||||
chart = metro.get_artist_chart()
|
||||
|
||||
# Assert
|
||||
self.assertEqual(type(chart[0]), pylast.TopItem)
|
||||
self.assertEqual(type(chart[0].item), pylast.Artist)
|
||||
|
||||
def test_get_metro_weekly_chart_dates(self):
|
||||
# Arrange
|
||||
# Act
|
||||
dates = self.network.get_metro_weekly_chart_dates()
|
||||
|
||||
# Assert
|
||||
self.assertGreaterEqual(len(dates), 1)
|
||||
self.assertEqual(type(dates[0]), tuple)
|
||||
(start, end) = dates[0]
|
||||
self.assertLess(start, end)
|
||||
|
||||
def test_geo_get_metros(self):
|
||||
# Arrange
|
||||
# Act
|
||||
|
|
Loading…
Reference in a new issue