This Python script automates the process of scraping Billboard's Hot 100 songs for a specified date and creating a private playlist on Spotify with those songs. It utilizes web scraping with BeautifulSoup and interacts with the Spotify API using the Spotipy library.
- Python 3.x installed on your system.
pip install beautifulsoup4 requests spotipy python-dotenv
- Create a Spotify Developer account at Spotify Developer Dashboard.
- Create a new application to obtain Client ID and Client Secret.
- Log in to your Spotify Developer account and create a new application.
- Note down the Client ID and Client Secret provided for your application.
- In your Spotify application settings, add
http://example.com
as a Redirect URI.
- Create a file named
.env
in the same directory as your Python script. - Add the following lines to the
.env
file, replacing placeholders with your actual credentials:
SPOTIFY_APP_CLIENT=your_client_id
SPOTIFY_APP_CLIENT_SECRET=your_client_secret
SPOTIFY_REDIRECT_URL=http://example.com
- Create an empty file named
token.txt
in the same directory as your Python script.
- Open a terminal or command prompt.
- Navigate to the directory containing your Python script and
.env
file. - Run the script using Python:
python main.py
- Enter the date in the format
YYYY-MM-DD
when prompted. This date specifies the Billboard Hot 100 chart to scrape. - Enter a custom name for the playlist you want to create on Spotify.
- The script will open a web browser for you to log in to Spotify (if not already authenticated) and authorize the application.
- This step grants the script permission to create a playlist and add songs to your Spotify account.
- The script uses
requests
andBeautifulSoup
to scrape Billboard's Hot 100 songs page for the specified date. - It extracts the song titles from the HTML response.
- Authentication with Spotify is handled using
spotipy
andSpotifyOAuth
. - The script prompts for Spotify login and authorization via the web browser.
- It requests necessary permissions (
playlist-modify-private
andplaylist-read-private
) to manage playlists on your behalf.
- For each song title scraped from Billboard, the script searches Spotify for a matching track from the same year.
- If found, the Spotify URI for the track is collected.
- After collecting Spotify URIs for all matching tracks, the script prompts for a custom playlist name.
- It creates a new private playlist on your Spotify account with the specified name and adds the collected songs.
- Upon successful completion, the script confirms the playlist creation and exits.