-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19ef875
commit cd7e881
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from musixmatch.client import Client | ||
from musixmatch.models import Artist as ArtistModel | ||
from musixmatch.models import Track as TrackModel | ||
|
||
|
||
class Chart(Client): | ||
"""Chart operations.""" | ||
MAX_PAGE_SIZE = 99 | ||
|
||
def __init__(self, **kwargs): | ||
super(Chart, self).__init__(**kwargs) | ||
self.fields_tag = "fields" | ||
|
||
def artists(self, country, page=1, page_size=MAX_PAGE_SIZE): | ||
""" | ||
Get the list of the top artists of a given country. | ||
:type country: string | ||
:type page: double | ||
:type page_size: double | ||
:param country: A valid country code. | ||
:param page: Define the page number for paginated results. | ||
:param page_size: Define the page size for paginated results. Range is 1 to 99. | ||
:return [List]: Tracks List. | ||
""" | ||
assert page_size <= self.MAX_PAGE_SIZE, "Page size must be lower than %s" % self.MAX_PAGE_SIZE | ||
url = "/chart.artists.get" | ||
params = {"country": country, "page": page, "page_size": page_size + 1} | ||
result = self._get(url, params=params) | ||
artist_list = map(lambda x: x["artist"], result["message"]["body"]["artist_list"]) | ||
return ArtistModel._parse_list(artist_list) |