<reponame>PoliTwit1984/Politwitverse<gh_stars>1-10
import billboard
import config
import spotipy
from spotipy.oauth2 import SpotifyOAuth

chart = billboard.ChartData("hot-100", date="2003-10-08")

scope = "playlist-modify-public"
username = "12939482"

token = SpotifyOAuth(
    client_id=config.spot_id,
    client_secret=config.spot_secret,
    scope=scope,
    redirect_uri="http://example.com",
    username=username,
)
sp = spotipy.Spotify(auth_manager=token)

playlist_name = input("Enter a date YYYY-MM-DD for playlist: ")

playlist_description = "Top 100 songs from " + playlist_name

sp.user_playlist_create(
    user=username, name=playlist_name, public=True, description=playlist_description
)

chart = billboard.ChartData("hot-100", date=playlist_name)

list_of_songs = []
try:
    for song in chart:
        result = sp.search(q=song.title, type="track", limit=1)
        print(result["tracks"]["items"][0]["uri"], song.title)
        list_of_songs.append(result["tracks"]["items"][0]["uri"])
    
except:
    pass

pp = sp.user_playlists(user=username)
playlist = pp["items"][0]["id"]

sp.user_playlist_add_tracks(user=username, playlist_id=playlist, tracks=list_of_songs)

import billboard
import config
import spotipy
from spotipy.oauth2 import SpotifyOAuth

chart = billboard.ChartData("hot-100", date="2003-10-08")

scope = "playlist-modify-public"
username = "12939482"

token = SpotifyOAuth(
    client_id=config.spot_id,
    client_secret=config.spot_secret,
    scope=scope,
    redirect_uri="http://example.com",
    username=username,
)
sp = spotipy.Spotify(auth_manager=token)

playlist_name = input("Enter a date YYYY-MM-DD for playlist: ")

playlist_description = "Top 100 songs from " + playlist_name

sp.user_playlist_create(
    user=username, name=playlist_name, public=True, description=playlist_description
)

chart = billboard.ChartData("hot-100", date=playlist_name)

list_of_songs = []
try:
    for song in chart:
        result = sp.search(q=song.title, type="track", limit=1)
        print(result["tracks"]["items"][0]["uri"], song.title)
        list_of_songs.append(result["tracks"]["items"][0]["uri"])
    
except:
    pass

pp = sp.user_playlists(user=username)
playlist = pp["items"][0]["id"]

sp.user_playlist_add_tracks(user=username, playlist_id=playlist, tracks=list_of_songs)