removed a file
This commit is contained in:
parent
01d9b97dca
commit
16b9359e89
Binary file not shown.
@ -1,47 +0,0 @@
|
|||||||
from bs4 import BeautifulSoup
|
|
||||||
import requests
|
|
||||||
import spotipy
|
|
||||||
from spotipy.oauth2 import SpotifyOAuth
|
|
||||||
|
|
||||||
# Scraping Billboard 100
|
|
||||||
date = input("Which year do you want to travel to? Type the date in this format YYYY-MM-DD: ")
|
|
||||||
header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0"}
|
|
||||||
billboard_url = "https://www.billboard.com/charts/hot-100/" + date
|
|
||||||
response = requests.get(url=billboard_url, headers=header)
|
|
||||||
|
|
||||||
soup = BeautifulSoup(response.text, 'html.parser')
|
|
||||||
song_names_spans = soup.select("li ul li h3")
|
|
||||||
song_names = [song.getText().strip() for song in song_names_spans]
|
|
||||||
|
|
||||||
# Spotify Authentication
|
|
||||||
sp = spotipy.Spotify(
|
|
||||||
auth_manager=SpotifyOAuth(
|
|
||||||
scope="playlist-modify-private",
|
|
||||||
redirect_uri="https://www.billboard.com/charts/hot-100/",
|
|
||||||
client_id="your-spotify-devloper-client-id-here",
|
|
||||||
client_secret="your-spotify-devloper-client-secret-here",
|
|
||||||
show_dialog=True,
|
|
||||||
cache_path="token.txt"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
user_id = sp.current_user()["id"]
|
|
||||||
print(user_id)
|
|
||||||
|
|
||||||
# Searching Spotify for songs by title
|
|
||||||
song_uris = []
|
|
||||||
year = date.split("-")[0]
|
|
||||||
for song in song_names:
|
|
||||||
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} 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)
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
beautifulsoup4==4.12.3
|
|
||||||
spotipy==2.24.0
|
|
||||||
requests==2.32.3
|
|
||||||
Loading…
Reference in New Issue
Block a user