Remove dead Last.fm metro methods

This commit is contained in:
hugovk 2017-09-26 08:58:37 +03:00
parent 230439f52f
commit 27ba0dd6b3
2 changed files with 0 additions and 292 deletions

View file

@ -230,13 +230,6 @@ class _Network(object):
return Country(country_name, self)
def get_metro(self, metro_name, country_name):
"""
Returns a metro object
"""
return Metro(metro_name, country_name, self)
def get_user(self, username):
"""
Returns a user object
@ -332,46 +325,6 @@ class _Network(object):
return seq
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:
country (Optional) : Optionally restrict the results to those Metros
from a particular country, as defined by the ISO 3166-1 country
names standard.
"""
params = {}
if country:
params["country"] = country
doc = _Request(self, "geo.getMetros", params).execute(cacheable)
metros = doc.getElementsByTagName("metro")
seq = []
for metro in metros:
name = _extract(metro, "name")
country = _extract(metro, "country")
seq.append(Metro(name, country, self))
return seq
def get_geo_top_artists(self, country, limit=None, cacheable=True):
"""Get the most popular artists on Last.fm by country.
Parameters:
@ -1912,169 +1865,6 @@ class Country(_BaseObject):
domain_name, "country") % {'country_name': country_name}
class Metro(_BaseObject):
"""A metro at Last.fm."""
name = None
country = None
__hash__ = _BaseObject.__hash__
def __init__(self, name, country, network):
_BaseObject.__init__(self, network, None)
self.name = name
self.country = country
def __repr__(self):
return "pylast.Metro(%s, %s, %s)" % (
repr(self.name), repr(self.country), repr(self.network))
@_string_output
def __str__(self):
return self.get_name() + ", " + self.get_country()
def __eq__(self, other):
return (self.get_name().lower() == other.get_name().lower() and
self.get_country().lower() == other.get_country().lower())
def __ne__(self, other):
return (self.get_name() != other.get_name() or
self.get_country().lower() != other.get_country().lower())
def _get_params(self):
return {'metro': self.get_name(), 'country': self.get_country()}
def get_name(self):
"""Returns the metro name."""
return self.name
def get_country(self):
"""Returns the metro country."""
return self.country
def _get_chart(
self, method, tag="artist", limit=None, from_date=None,
to_date=None, cacheable=True):
"""Internal helper for getting geo charts."""
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(method, cacheable, params)
seq = []
for node in doc.getElementsByTagName(tag):
if tag == "artist":
item = Artist(_extract(node, "name"), self.network)
elif tag == "track":
title = _extract(node, "name")
artist = _extract_element_tree(node).get('artist')['name']
item = Track(artist, title, self.network)
else:
return None
weight = _number(_extract(node, "listeners"))
seq.append(TopItem(item, weight))
return seq
def get_artist_chart(
self, tag="artist", limit=None, from_date=None, to_date=None,
cacheable=True):
"""Get a chart of artists for a metro.
Parameters:
from_date (Optional) : Beginning timestamp of the weekly range
requested
to_date (Optional) : Ending timestamp of the weekly range requested
limit (Optional) : The number of results to fetch per page.
Defaults to 50.
"""
return self._get_chart(
"geo.getMetroArtistChart", tag=tag, limit=limit,
from_date=from_date, to_date=to_date, cacheable=cacheable)
def get_hype_artist_chart(
self, tag="artist", limit=None, from_date=None, to_date=None,
cacheable=True):
"""Get a chart of hyped (up and coming) artists for a metro.
Parameters:
from_date (Optional) : Beginning timestamp of the weekly range
requested
to_date (Optional) : Ending timestamp of the weekly range requested
limit (Optional) : The number of results to fetch per page.
Defaults to 50.
"""
return self._get_chart(
"geo.getMetroHypeArtistChart", tag=tag, limit=limit,
from_date=from_date, to_date=to_date, cacheable=cacheable)
def get_unique_artist_chart(
self, tag="artist", limit=None, from_date=None, to_date=None,
cacheable=True):
"""Get a chart of the artists which make that metro unique.
Parameters:
from_date (Optional) : Beginning timestamp of the weekly range
requested
to_date (Optional) : Ending timestamp of the weekly range requested
limit (Optional) : The number of results to fetch per page.
Defaults to 50.
"""
return self._get_chart(
"geo.getMetroUniqueArtistChart", tag=tag, limit=limit,
from_date=from_date, to_date=to_date, cacheable=cacheable)
def get_track_chart(
self, tag="track", limit=None, from_date=None, to_date=None,
cacheable=True):
"""Get a chart of tracks for a metro.
Parameters:
from_date (Optional) : Beginning timestamp of the weekly range
requested
to_date (Optional) : Ending timestamp of the weekly range requested
limit (Optional) : The number of results to fetch per page.
Defaults to 50.
"""
return self._get_chart(
"geo.getMetroTrackChart", tag=tag, limit=limit,
from_date=from_date, to_date=to_date, cacheable=cacheable)
def get_hype_track_chart(
self, tag="track", limit=None, from_date=None, to_date=None,
cacheable=True):
"""Get a chart of tracks for a metro.
Parameters:
from_date (Optional) : Beginning timestamp of the weekly range
requested
to_date (Optional) : Ending timestamp of the weekly range requested
limit (Optional) : The number of results to fetch per page.
Defaults to 50.
"""
return self._get_chart(
"geo.getMetroHypeTrackChart", tag=tag,
limit=limit, from_date=from_date, to_date=to_date,
cacheable=cacheable)
def get_unique_track_chart(
self, tag="track", limit=None, from_date=None, to_date=None,
cacheable=True):
"""Get a chart of tracks for a metro.
Parameters:
from_date (Optional) : Beginning timestamp of the weekly range
requested
to_date (Optional) : Ending timestamp of the weekly range requested
limit (Optional) : The number of results to fetch per page.
Defaults to 50.
"""
return self._get_chart(
"geo.getMetroUniqueTrackChart", tag=tag, limit=limit,
from_date=from_date, to_date=to_date, cacheable=cacheable)
class Library(_BaseObject):
"""A user's Last.fm library."""

View file

@ -260,13 +260,6 @@ class TestPyLast(unittest.TestCase):
# Act/Assert
self.helper_is_thing_hashable(country)
def test_metro_is_hashable(self):
# Arrange
metro = self.network.get_metro("Helsinki", "Finland")
# Act/Assert
self.helper_is_thing_hashable(metro)
def test_library_is_hashable(self):
# Arrange
library = pylast.Library(user=self.username, network=self.network)
@ -578,67 +571,6 @@ class TestPyLast(unittest.TestCase):
(start, end) = dates[0]
self.assertLess(start, end)
def test_get_metro_weekly_chart_dates(self):
# Arrange
# Act
dates = self.network.get_metro_weekly_chart_dates()
# Assert
self.helper_dates_valid(dates)
def helper_geo_chart(self, function_name, expected_type=pylast.Artist):
# Arrange
metro = self.network.get_metro("Madrid", "Spain")
dates = self.network.get_metro_weekly_chart_dates()
(from_date, to_date) = dates[0]
# get metro.function_name()
func = getattr(metro, function_name, None)
# Act
chart = func(from_date=from_date, to_date=to_date, limit=1)
# Assert
self.assertEqual(len(chart), 1)
self.assertIsInstance(chart[0], pylast.TopItem)
self.assertIsInstance(chart[0].item, expected_type)
def test_get_metro_artist_chart(self):
# Arrange/Act/Assert
self.helper_geo_chart("get_artist_chart")
def test_get_metro_hype_artist_chart(self):
# Arrange/Act/Assert
self.helper_geo_chart("get_hype_artist_chart")
def test_get_metro_unique_artist_chart(self):
# Arrange/Act/Assert
self.helper_geo_chart("get_unique_artist_chart")
def test_get_metro_track_chart(self):
# Arrange/Act/Assert
self.helper_geo_chart("get_track_chart", expected_type=pylast.Track)
def test_get_metro_hype_track_chart(self):
# Arrange/Act/Assert
self.helper_geo_chart(
"get_hype_track_chart", expected_type=pylast.Track)
def test_get_metro_unique_track_chart(self):
# Arrange/Act/Assert
self.helper_geo_chart(
"get_unique_track_chart", expected_type=pylast.Track)
def test_geo_get_metros(self):
# Arrange
# Act
metros = self.network.get_metros(country="Poland")
# Assert
self.assertGreaterEqual(len(metros), 1)
self.assertIsInstance(metros[0], pylast.Metro)
self.assertEqual(metros[0].get_country(), "Poland")
def test_geo_get_top_artists(self):
# Arrange
# Act
@ -661,20 +593,6 @@ class TestPyLast(unittest.TestCase):
self.assertIsInstance(tracks[0], pylast.TopItem)
self.assertIsInstance(tracks[0].item, pylast.Track)
def test_metro_class(self):
# Arrange
# Act
metro = self.network.get_metro("Bergen", "Norway")
# Assert
self.assertEqual(metro.get_name(), "Bergen")
self.assertEqual(metro.get_country(), "Norway")
self.assertEqual(str(metro), "Bergen, Norway")
self.assertEqual(metro, pylast.Metro("Bergen", "Norway", self.network))
self.assertNotEqual(
metro,
pylast.Metro("Wellington", "New Zealand", self.network))
def helper_at_least_one_thing_in_top_list(self, things, expected_type):
# Assert
self.assertGreater(len(things), 1)