Skip to content

Commit 4b6fb63

Browse files
committed
added filter
1 parent 005a943 commit 4b6fb63

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

ChillBot/music.py

+32-9
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ class TrackItem:
1818
Type: int
1919
"""
2020

21-
2221
@dataclass(frozen=True)
23-
class ArtistListItem:
24-
"""Artist data list"""
22+
class ArtistItem:
23+
"""Gets the artist data"""
2524

2625
name: str
2726
"""The name of the artist
@@ -34,6 +33,28 @@ class ArtistListItem:
3433
Type: list[TrackItem]
3534
"""
3635

36+
@dataclass(frozen=True)
37+
class ArtistList:
38+
"""Artist data list"""
39+
40+
artists: list[ArtistItem]
41+
"""The name of the artist
42+
43+
Type: list[ArtistItem]
44+
"""
45+
46+
def __init__(self):
47+
super().__init__()
48+
49+
def filter(self, name: str):
50+
51+
data = [x for x in self.artists if x.get('name').lower() == name.lower()]
52+
53+
if len(data) == 0:
54+
return None
55+
56+
return ArtistItem(data[0].get('name'), [TrackItem(x, y) for x, y in data[0].get('tracks').items()])
57+
3758

3859
@dataclass(frozen=True)
3960
class MusicResponse:
@@ -44,10 +65,10 @@ class MusicResponse:
4465
4566
Type: int
4667
"""
47-
artists: list[ArtistListItem]
68+
artists: list[ArtistList]
4869
"""Returns the list of artists
4970
50-
Type: list[ArtistListItem]
71+
Type: list[ArtistList]
5172
"""
5273

5374

@@ -75,8 +96,10 @@ async def get_top_ten(id: str):
7596

7697
return MusicResponse(
7798
json_response.get('_id'),
78-
[ArtistListItem(
79-
x.get('name'),
80-
[TrackItem(x, y) for x, y in x.get('tracks').items()]
81-
) for x in json_response.get('artists')]
99+
ArtistList(
100+
[ArtistItem(
101+
x.get('name'),
102+
[TrackItem(x, y) for x, y in x.get('tracks').items()]
103+
) for x in json_response.get('artists')]
104+
)
82105
)

0 commit comments

Comments
 (0)