Skip to content

Instantly share code, notes, and snippets.

@TheMuellenator
Forked from angelabauer/main.py
Last active March 17, 2026 19:32
Show Gist options
  • Select an option

  • Save TheMuellenator/c84616c21f0f9ce68c12c357d3e1c794 to your computer and use it in GitHub Desktop.

Select an option

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)
@dheerajdhami2001-cyber

dheerajdhami2001-cyber commented Dec 14, 2025 •

Copy link
Copy Markdown

I think now the billboard is only giving list to subscribers
Screenshot 2025-12-14 at 7 00 47 PM

@rukkho

rukkho commented Mar 17, 2026

Copy link
Copy Markdown

PLEASE I NEED HELP WHY THIS CODE DOESN'T WORK FOR ME?

import requests from bs4 import BeautifulSoup import spotipy from spotipy.oauth2 import SpotifyOAuth

CLIENT_ID = "9067a23713c34ea68d7276265816c720" CLIENT_SECRET = "334e6b70064546b092ad6b355ec171db"

url = "https://www.billboard.com/charts/hot-100/"

date = input("Which year do you want to travel to? Type the date in this Format YY-MM-DD.")

response = requests.get(f"{url}{date}") web = response.text

soup = BeautifulSoup(web, "html.parser")

musics = soup.find_all("h3", "a-no-trucate") music_titles = [] for music in musics: title = music.get_text().strip() music_titles.append(title)

sp = spotipy.Spotify( auth_manager=SpotifyOAuth( scope="playlist-modify-private", redirect_uri="http://example.com", client_id=CLIENT_ID, client_secret=CLIENT_SECRET, show_dialog=True, cache_path="token.txt" ) )

user_id = sp.current_user()["id"]

song_uris = [] year = date.split("-")[0] for song in music_titles: result = sp.search(q=f"track:{song} year:{year}", type="track") # print(result) # print("space\n\n") try: uri = result["tracks"]["items"][0] song_uris.append(uri) except IndexError: print(f"{song} doesn't exist in Spotify. Skipped.")

Creating a new private playlist in Spotify

playlist = sp.user_playlist_create(user=user_id, name=f"{date} Billboard 100", public=False) print(playlist)

Adding songs found into the new playlist

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

print(playlist['id'])

It didn't work because you didn't target the "uri". Note what you did:

uri = result["tracks"]["items"][0] instead:
uri = result["tracks"]["items"][0]["uri"]

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