mirror of
https://github.com/Dvorinka/SpotifyRecAlg.git
synced 2026-06-04 20:43:04 +00:00
first commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
from dataclasses import asdict
|
||||
|
||||
from swingmusic.models.artist import Artist
|
||||
|
||||
|
||||
def serialize_for_card(artist: Artist, include: set[str] = None):
|
||||
if include is None:
|
||||
include = set()
|
||||
try:
|
||||
artist_dict = asdict(artist)
|
||||
except TypeError:
|
||||
return {}
|
||||
|
||||
props_to_remove = {
|
||||
"is_favorite",
|
||||
"trackcount",
|
||||
"duration",
|
||||
"albumcount",
|
||||
"playcount",
|
||||
"playduration",
|
||||
"lastplayed",
|
||||
"id",
|
||||
"genres",
|
||||
"genrehashes",
|
||||
"extra",
|
||||
"created_date",
|
||||
"date",
|
||||
"fav_userids",
|
||||
"_score",
|
||||
}
|
||||
|
||||
if include:
|
||||
props_to_remove = props_to_remove - include
|
||||
|
||||
for key in props_to_remove:
|
||||
artist_dict.pop(key, None)
|
||||
|
||||
artist_dict["type"] = "artist"
|
||||
return artist_dict
|
||||
|
||||
|
||||
def serialize_for_cards(artists: list[Artist]):
|
||||
return [serialize_for_card(a) for a in artists]
|
||||
Reference in New Issue
Block a user