This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| artistImageUrlList = [] | |
| print('Total artists streamed:', len(uniqueArtistUriList)) | |
| for uri in range(49): | |
| spotifyUrl = requests.get('https://open.spotify.com/artist/' + | |
| str(uniqueArtistUriList[uri])) | |
| spoifyHtmlData = str(soup(spotifyUrl.text, 'html.parser')) | |
| spoifyHtmlData = spoifyHtmlData.split('<') | |
| artistName = spoifyHtmlData[5].split('>') | |
| artistName = artistName[1].split('|') | |
| artistApiResults = requests.get('https://api.spotify.com/v1/search', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cid = '' | |
| secret = '' | |
| username = '' | |
| redirect_uri = 'http://localhost:8888/callback' | |
| scope = 'user-top-read playlist-modify-public' | |
| token = util.prompt_for_user_token(username, scope, | |
| client_id = cid, client_secret = secret, redirect_uri = redirect_uri) | |
| if token: | |
| sp = spotipy.Spotify(auth = token) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| artistUriDf = pd.DataFrame(list(zip(rankList, trackList, trackUriList, streamList, | |
| artistUriList)), columns = ['Rank', 'Track', 'Track URI', 'Streams', 'Artist URI']) | |
| for row in artistUriDf.index: | |
| if(artistUriDf['Artist URI'][row] == 'Error'): | |
| artistUriDf.drop([row], axis = 0, inplace = True) | |
| artistUriDfPivot = artistUriDf.pivot_table(index = ['Artist URI'], | |
| values = ['Streams'], aggfunc = 'sum').reset_index('Artist URI') | |
| artistUriDfPivot = artistUriDfPivot.sort_values(by = 'Streams', ascending = False | |
| rankList = [] | |
| for artist in range(artistUriDfPivot.shape[0]): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| artistUriList = [] | |
| print('Total Tracks:', len(trackUriList)) | |
| for uri in range(len(trackUriList)): | |
| goodLink = False | |
| while not goodLink: | |
| spotifyUrl = requests.get('https://open.spotify.com/track/' + | |
| str(trackUriList[uri])) | |
| if('200' in str(spotifyUrl)): | |
| goodLink = True | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for image in range(len(albumImageUrlList)): | |
| albumImageUrl = requests.get(albumImageUrlList[image]) | |
| filename = 'album_' + str(image+1) + '.png' | |
| with open(os.path.join(imageFolderPath, filename), 'wb') as out: | |
| out.write(albumImageUrl.content) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| albumImageUrlList = [] | |
| for uri in range(49): | |
| spotifyUrl = requests.get('https://open.spotify.com/album/' + | |
| str(uniqueAlbumUriList[uri])) | |
| bodyText = str(soup(spotifyUrl.text, 'html.parser')) | |
| bodyTextInfo = bodyText.split('<') | |
| albumImageData = bodyTextInfo[24] | |
| albumImageData = albumImageData.split('"') | |
| albumImageUrlList.append(albumImageData[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| albumUriDf = pd.DataFrame(list(zip(rankList, trackList, streamList, albumUriList)), | |
| columns = ['Rank', 'Track', 'Streams', 'Album URI']) | |
| albumUriDfPivot = albumUriDf.pivot_table(index = ['Album URI'], | |
| values = ['Streams'], aggfunc = 'sum').reset_index('Album URI') | |
| albumUriDfPivot = albumUriDfPivot.sort_values(by = 'Streams', ascending = False) | |
| rankList = [] | |
| for album in range(albumUriDfPivot.shape[0]): | |
| rankList.append(album+1) | |
| albumUriDfPivot.insert(0, 'Rank', rankList) | |
| uniqueAlbumUriList = albumUriDfPivot['Album URI'].tolist() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print('Total Tracks:', len(trackUriList)) | |
| for uri in range(len(trackUriList)): | |
| spotifyUrl = requests.get('https://open.spotify.com/track/' + str(trackUriList[uri])) | |
| spoifyHtmlData = soup(spotifyUrl.text, 'html.parser') | |
| divData = str(spoifyHtmlData.find('div', {'class': 'TS85Qkpioa31wR0p4kzT'})) | |
| if(divData != 'None'): | |
| divData = divData.split('=') | |
| albumUrl = divData[5] | |
| albumUrl = albumUrl.split('"') | |
| albumUriList.append(albumUrl[1].replace('/album/', '')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| path = r'' #path of your spotify top tracks excel file | |
| outputPath = '' #path where to output your spotify grid | |
| imageFolderPath = '' #path for the folder that will store album cover images | |
| data = pd.read_excel(path) | |
| rankList = (data['Rank']).tolist() | |
| trackList = (data['Track']).tolist() | |
| streamList = (data['Streams']).tolist() | |
| trackUriList = (data['URI']).tolist() | |
| albumUriList = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mpi = 0 | |
| max_count = 0 | |
| unique_uri_list = [] | |
| for i in range(len(uri_list) - 1): | |
| if uri_list[i] == uri_list[i+1]: | |
| count = count + 1 | |
| if count > max_count: | |
| max_count = count | |
| mpi = i | |
| unique_uri_list.append(uri_list[i]) |