You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code was working fine all day for me, then I went for lunch and came back to create a new playlist and now it wont work.
Please help
It keeps running this line of code for half an hour, by which point I interrupt the process
playlist = sp.user_playlist_create(USERNAME, playlist_name, public=False, description=playlist_description)
Entire code is below
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import pandas as pd
playlist_name = '4th Do You!! Roundup 2023'
playlist_description = 'Charlie Bones web scrape'
print("Creating playlist.....")
playlist = sp.user_playlist_create(USERNAME, playlist_name, public=False, description=playlist_description)
print("Playlist has been created")
Search for each song in the CSV and add it to the playlist
for index, row in df_sorted_2.iterrows():
track_name = row['Track Title']
artist_name = row['Artist']
# Use the Spotify API to search for the track
try:
# Refine the search query by including the artist name
search_query = f'{track_name} artist:{artist_name}'
# Use the Spotify API to search for the track
results = sp.search(q=search_query, type='track', limit=1)
if results['tracks']['items']:
track_uri = results['tracks']['items'][0]['uri']
# Add the track to the playlist
sp.playlist_add_items(playlist['id'], [track_uri])
else:
print(f"Track not found: {track_name} by {artist_name}")
except spotipy.SpotifyException as e:
print(f"Error searching for {track_name} by {artist_name}: {e}")
# Continue to the next iteration of the loop if there's an error
continue
print(f"Playlist '{playlist_name}' created successfully.")
The text was updated successfully, but these errors were encountered:
This code was working fine all day for me, then I went for lunch and came back to create a new playlist and now it wont work.
Please help
It keeps running this line of code for half an hour, by which point I interrupt the process
playlist = sp.user_playlist_create(USERNAME, playlist_name, public=False, description=playlist_description)
Entire code is below
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import pandas as pd
df_sorted_2 = pd.read_csv('/Documents/coding_projects/partoo/new_radio_round_up.csv')
Spotify API credentials
CLIENT_ID = client_id
CLIENT_SECRET = client_secret
REDIRECT_URI = 'http://localhost:3000'
USERNAME = username
Set up Spotify authentication
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
redirect_uri=REDIRECT_URI,
scope='playlist-modify-private'))
Create a new playlist
playlist_name = '4th Do You!! Roundup 2023'
playlist_description = 'Charlie Bones web scrape'
print("Creating playlist.....")
playlist = sp.user_playlist_create(USERNAME, playlist_name, public=False, description=playlist_description)
print("Playlist has been created")
Search for each song in the CSV and add it to the playlist
for index, row in df_sorted_2.iterrows():
track_name = row['Track Title']
artist_name = row['Artist']
# Use the Spotify API to search for the track
try:
# Refine the search query by including the artist name
search_query = f'{track_name} artist:{artist_name}'
print(f"Playlist '{playlist_name}' created successfully.")
The text was updated successfully, but these errors were encountered: