Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"access_token": "BQDIoM3hsbz1vXS1ZVn1ygK5GWHQL_tdf7GHrMKWyFtGNXblvgdOEC1n0mKo4Gun4MsI_j0bhQrbPUfOlJXMEBstomovptc6gSIjzDxt-OJs8sXJJd0BX_qXB70fUKmqqTzjVgHJge0", "token_type": "Bearer", "expires_in": 3600, "expires_at": 1777225601}
56 changes: 44 additions & 12 deletions lab-apis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "29694252-f217-454d-8881-681b2b6eeb1e",
"metadata": {},
"outputs": [],
"source": [
"# Your answer here"
"execution_count": 14,
"id": "d52bdc8b",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"HTTP Error for GET to https://api.spotify.com/v1/search with Params: {'q': 'Los Fabulosos Cadillacs', 'limit': 1, 'offset': 0, 'type': 'artist', 'market': None} returned 403 due to Active premium subscription required for the owner of the app. When the subscription status changes, it can take a few hours before requests are allowed again.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"http status: 403, code: -1 - https://api.spotify.com/v1/search?q=Los+Fabulosos+Cadillacs&limit=1&offset=0&type=artist:\n",
" Active premium subscription required for the owner of the app. When the subscription status changes, it can take a few hours before requests are allowed again., reason: None\n"
]
}
],
"source": [
"import spotipy; from spotipy.oauth2 import SpotifyClientCredentials; CLIENT_ID=\"AQUI_TU_CLIENT_ID\"; CLIENT_SECRET=\"AQUI_TU_CLIENT_SECRET\"; sp=spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)); artists=[\"Los Fabulosos Cadillacs\",\"Manu Chao\",\"Muchachito Bombo Infierno\"]; get_top_tracks=lambda a: (lambda r: [t[\"name\"] for t in sp.artist_top_tracks(r[\"artists\"][\"items\"][0][\"id\"])[\"tracks\"][:5]])(sp.search(q=a, type=\"artist\", limit=1)); find_related_artists=lambda a: (lambda r: [x[\"name\"] for x in sp.artist_related_artists(r[\"artists\"][\"items\"][0][\"id\"])[\"artists\"][:5]])(sp.search(q=a, type=\"artist\", limit=1)); top_tracks_list=[]; related_artists_list=[]; playlist=[]; exec('try:\\n top_tracks_list=[get_top_tracks(a) for a in artists]\\n related_artists_list=[find_related_artists(a) for a in artists]\\n playlist=list(dict.fromkeys([t for tracks in top_tracks_list for t in tracks]+[t for group in related_artists_list for artist in group for t in get_top_tracks(artist)]))\\n print(top_tracks_list)\\n print(related_artists_list)\\n print(playlist)\\nexcept Exception as e:\\n print(e)')"
]
},
{
Expand Down Expand Up @@ -533,18 +549,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"id": "ed92d961-9646-4375-a386-ccc320a958f5",
"metadata": {},
"outputs": [],
"source": [
"# Your answer here"
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"HTTP Error for GET to https://api.spotify.com/v1/browse/featured-playlists with Params: {'locale': None, 'country': None, 'timestamp': None, 'limit': 5, 'offset': 0} returned 403 due to Active premium subscription required for the owner of the app. When the subscription status changes, it can take a few hours before requests are allowed again.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"http status: 403, code: -1 - https://api.spotify.com/v1/browse/featured-playlists?limit=5&offset=0:\n",
" Active premium subscription required for the owner of the app. When the subscription status changes, it can take a few hours before requests are allowed again., reason: None\n"
]
}
],
"source": [
"import spotipy; from spotipy.oauth2 import SpotifyClientCredentials; CLIENT_ID=\"AQUI_TU_CLIENT_ID\"; CLIENT_SECRET=\"AQUI_TU_CLIENT_SECRET\"; sp=spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)); exec('try:\\n featured=sp.featured_playlists(limit=5)\\n top5=[(p[\\\"name\\\"],p[\\\"id\\\"]) for p in featured[\\\"playlists\\\"][\\\"items\\\"][:5]]\\n chosen_id=top5[0][1]\\n chosen_playlist=sp.playlist(chosen_id)\\n playlist_name=chosen_playlist[\\\"name\\\"]\\n playlist_description=chosen_playlist[\\\"description\\\"]\\n total_tracks=chosen_playlist[\\\"tracks\\\"][\\\"total\\\"]\\n items=sp.playlist_items(chosen_id, limit=10)[\\\"items\\\"]\\n first_10_tracks=[item[\\\"track\\\"][\\\"name\\\"] for item in items if item.get(\\\"track\\\")]\\n track_artists={item[\\\"track\\\"][\\\"name\\\"]:[artist[\\\"name\\\"] for artist in item[\\\"track\\\"][\\\"artists\\\"]] for item in items if item.get(\\\"track\\\")}\\n print(top5)\\n print(playlist_name)\\n print(playlist_description)\\n print(total_tracks)\\n print(first_10_tracks)\\n print(track_artists)\\nexcept Exception as e:\\n print(e)')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -558,7 +590,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.4"
}
},
"nbformat": 4,
Expand Down