File size: 2,347 Bytes
feb4627 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 4 10:48:49 2022
@author: halimbouayad
"""
import pandas as pd
import numpy as np
from datetime import datetime
import os
# #load data
# dir = os.getcwd()
# path = os.path.join(dir, 'data.csv')
# try:
# df=pd.read_csv(path)
# df_continent=pd.DataFrame(df.groupby('continent').total_deaths.sum())
# except:
# print('Error has occured')
# ################################################
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import json
import spotipy.util as util
from spotipy.oauth2 import SpotifyClientCredentials
import requests
from requests import *
import pandas as pd
import streamlit as st
# Custom imports
import ss_functions
from ss_functions import *
import env_variables
username = "hyder14"
st.title('Spotify Playlist Shuffler')
st.text('The goal of this project is to gain better control of your playlists\n while exploring the features of the Spotify Web API.')
with st.expander('Create a playlist'):
st.header('Create a playlist')
st.write('Hello, *World!* :sunglasses:')
scope = "playlist-modify-public"
token = util.prompt_for_user_token(username,scope,client_id=os.environ['SPOTIPY_CLIENT_ID'],client_secret=os.environ['SPOTIPY_CLIENT_SECRET'],redirect_uri=os.environ['SPOTIPY_REDIRECT_URI'])
spotifyObject = spotipy.Spotify(auth=token)
#create the playlist
playlist_name = st.text_input('Enter a playlist name = ')
playlist_description = st.text_input('Enter a playlist description = ')
if st.button('Create playlist!'):
token = util.prompt_for_user_token(username,scope,client_id=SPOTIPY_CLIENT_ID,client_secret=SPOTIPY_CLIENT_SECRET,redirect_uri=SPOTIPY_REDIRECT_URI)
spotifyObject = spotipy.Spotify(auth=token)
spotifyObject.user_playlist_create(user=username, name=playlist_name, public=True, description=playlist_description)
with st.expander('List of current playlists'):
st.header("List of playlist")
sp=connect(scope='user-library_read', username=username)
df, test=get_data(sp, username)
st.dataframe(df)
st.text(test)
with st.expander('What do your playlists look like?'):
if isinstance(df, pd.DataFrame):
EDA(df)
|