From 87fcdd2958609486a7552dcd849928259fe18e42 Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Fri, 1 Dec 2023 09:41:04 +0100 Subject: [PATCH] feat: update result display --- Spotify/Spotify_Get_Artist.ipynb | 94 ++++++++++---------------------- 1 file changed, 29 insertions(+), 65 deletions(-) diff --git a/Spotify/Spotify_Get_Artist.ipynb b/Spotify/Spotify_Get_Artist.ipynb index ef20d14b19..3367943242 100644 --- a/Spotify/Spotify_Get_Artist.ipynb +++ b/Spotify/Spotify_Get_Artist.ipynb @@ -30,7 +30,7 @@ "tags": [] }, "source": [ - "**Tags:** #spotify #api #getartist #webapi #reference #uniqueid" + "**Tags:** #spotify #api #getartist #webapi #reference #uniqueid #snippet" ] }, { @@ -52,7 +52,7 @@ "tags": [] }, "source": [ - "**Last update:** 2023-11-24 (Created: 2023-11-24)" + "**Last update:** 2023-12-01 (Created: 2023-11-24)" ] }, { @@ -63,7 +63,7 @@ "tags": [] }, "source": [ - "**Description:** This notebook retrieves Spotify catalog information for a single artist identified by their unique Spotify ID. It is useful for organizations to quickly access artist information from the Spotify API." + "**Description:** This notebook retrieves Spotify catalog information for a single artist identified by their unique Spotify ID." ] }, { @@ -103,16 +103,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "d1626996-b265-445d-842f-764d9f8a7778", "metadata": { - "execution": { - "iopub.execute_input": "2023-11-30T21:54:03.968079Z", - "iopub.status.busy": "2023-11-30T21:54:03.967580Z", - "iopub.status.idle": "2023-11-30T21:54:06.141271Z", - "shell.execute_reply": "2023-11-30T21:54:06.140310Z", - "shell.execute_reply.started": "2023-11-30T21:54:03.967987Z" - }, "papermill": {}, "tags": [] }, @@ -124,7 +117,8 @@ " !pip install spotipy --user\n", " import spotipy\n", "from spotipy.oauth2 import SpotifyClientCredentials\n", - "import naas" + "import naas\n", + "from IPython.display import Image, display" ] }, { @@ -143,16 +137,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "e6756fee-ce1a-4e99-88cf-ec27f70d65d6", "metadata": { - "execution": { - "iopub.execute_input": "2023-11-30T21:54:06.143155Z", - "iopub.status.busy": "2023-11-30T21:54:06.142672Z", - "iopub.status.idle": "2023-11-30T21:54:06.341082Z", - "shell.execute_reply": "2023-11-30T21:54:06.340490Z", - "shell.execute_reply.started": "2023-11-30T21:54:06.143120Z" - }, "papermill": {}, "tags": [] }, @@ -199,37 +186,25 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "10ea4a46-c567-4fd5-8c3c-507c99b3b249", "metadata": { - "execution": { - "iopub.execute_input": "2023-11-30T21:54:06.344053Z", - "iopub.status.busy": "2023-11-30T21:54:06.343875Z", - "iopub.status.idle": "2023-11-30T21:54:06.349668Z", - "shell.execute_reply": "2023-11-30T21:54:06.349107Z", - "shell.execute_reply.started": "2023-11-30T21:54:06.344033Z" - }, "papermill": {}, "tags": [] }, "outputs": [], "source": [ "def get_artist(client_id, client_secret, artist_id):\n", + " data = None\n", " sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials(client_id=client_id, client_secret=client_secret))\n", - " \n", " try:\n", - " artist = sp.artist(artist_id)\n", - " \n", - " return {\n", - " \"Name\": artist['name'],\n", - " \"Genres\": artist['genres'],\n", - " \"Popularity\": artist['popularity'],\n", - " \"Followers\": artist['followers']['total'],\n", - " \"External URLs\": artist['external_urls'],\n", - " }\n", + " data = sp.artist(artist_id)\n", " except spotipy.SpotifyException as e:\n", " print(f\"Error retrieving artist information: {e}\")\n", - " return None" + " return data\n", + " \n", + "data = get_artist(client_id, client_secret, artist_id)\n", + "data" ] }, { @@ -265,40 +240,29 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "d1b83be8-4b23-4078-8a7f-7f2810dfe114", "metadata": { - "execution": { - "iopub.execute_input": "2023-11-30T21:54:06.352042Z", - "iopub.status.busy": "2023-11-30T21:54:06.351883Z", - "iopub.status.idle": "2023-11-30T21:54:06.513641Z", - "shell.execute_reply": "2023-11-30T21:54:06.513048Z", - "shell.execute_reply.started": "2023-11-30T21:54:06.352025Z" - }, "papermill": {}, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Artist Information:\n", - "Name: Beyoncé\n", - "Genres: ['pop', 'r&b']\n", - "Popularity: 83\n", - "Followers: 36497674\n", - "External URLs: {'spotify': 'https://open.spotify.com/artist/6vWDO969PvNqNYHIOW5v0m'}\n" - ] - } - ], + "outputs": [], "source": [ - "artist_info = get_artist(client_id, client_secret, artist_id)\n", - "\n", - "if artist_info:\n", + "if data:\n", + " artist_info = {\n", + " \"Name\": data['name'],\n", + " \"Genres\": data['genres'],\n", + " \"Popularity\": data['popularity'],\n", + " \"Followers\": data['followers']['total'],\n", + " \"External URLs\": data['external_urls'].get(\"spotify\"),\n", + " \"Image\": data['images'][0].get(\"url\"),\n", + " }\n", " print(\"Artist Information:\")\n", " for key, value in artist_info.items():\n", - " print(f\"{key}: {value}\")\n", + " if key == \"Image\":\n", + " display(Image(url=value))\n", + " else:\n", + " print(f\"{key}: {value}\")\n", "else:\n", " print(\"Failed to retrieve artist information.\")" ]