Skip to content

Instantly share code, notes, and snippets.

@TheMuellenator
Forked from angelabauer/main.py
Last active October 31, 2025 02:33
Show Gist options
  • Save TheMuellenator/c84616c21f0f9ce68c12c357d3e1c794 to your computer and use it in GitHub Desktop.
Save TheMuellenator/c84616c21f0f9ce68c12c357d3e1c794 to your computer and use it in GitHub Desktop.
sp = spotipy.Spotify(
auth_manager=SpotifyOAuth(
scope="playlist-modify-private",
redirect_uri="http://example.com",
client_id=YOUR UNIQUE CLIENT ID,
client_secret= YOUR UNIQUE CLIENT SECRET,
show_dialog=True,
cache_path="token.txt"
)
)
user_id = sp.current_user()["id"]
date = input("Which year do you want to travel to? Type the date in this format YYYY-MM-DD: ")
song_uris = ["The list of", "song URIs", "you got by", "searching Spotify"]
playlist = sp.user_playlist_create(user=user_id, name=f"{date} Billboard 100", public=False)
# print(playlist)
sp.playlist_add_items(playlist_id=playlist["id"], items=song_uris)
@GreggRodgers02
Copy link

GreggRodgers02 commented Oct 31, 2025

As of October 2025, this code is working as attended for everyone reference

import requests
from bs4 import BeautifulSoup
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import os
from dotenv import load_dotenv

load_dotenv()

user_input = input('Which year do you want to travel to? Type the date in this format YYYY-MM-DD: ')

headers = {'User-Agent': 'MY USER AGENT'}

site_html = requests.get(f'https://www.billboard.com/charts/hot-100/{user_input}/', headers=headers).text
soup = BeautifulSoup(site_html, features='html.parser')

top_100 = soup.select('li ul li h3')
top_100_list = [songs.text.strip().replace('\n', '').replace('\t', '') for songs in top_100]

#print(top_100_list)
sp = spotipy.Spotify(
    auth_manager=SpotifyOAuth(
        client_id=os.getenv('SPOTIFY_CLIENT_ID'),
        client_secret=os.getenv('SPOTIFY_CLIENT_SECRET'),
        scope='playlist-modify-private',
        cache_path='token.txt',
        redirect_uri='http://127.0.0.1:9090',
        show_dialog=True,
        username='g35k',
))
user_id = sp.current_user()["id"]

song_uris = []
year = user_input.split('-')[0]
print(year)
for song in top_100_list:
    result = sp.search(q=f'track:{song} year:{year}', type='track')
    print(result)
    try:
        uri=result['tracks']['items'][0]['uri']
        song_uris.append(uri)
    except IndexError:
        print(f'{song} not found')


playlist = sp.user_playlist_create(user=user_id, name=f'{user_input} Billboard 100', public=False)


sp.playlist_add_items(playlist_id=playlist['id'], `items=song_uris)```

I believe struggling to understand the API document is a benefit, Learning happen best when struggling lol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment