<jupyter_start><jupyter_text>Takes results of the Spotify saved songs scrape and collects lyrics using Genius API<jupyter_code>#import pandas as pd
import requests
import lyricsgenius as genius

#df = pd.read_pickle('starred_songs.pkl')
#songs = df[['artist_name', 'song_name']].values
access_token = '<KEY>'
base_url = "http://api.genius.com"
#Key line below here when, this is how to authorize your request when
#using the API
headers = {'Authorization': 'Bearer ' + access_token}
search_url = base_url + "/search"
song_title = "The Serpent is Kind (Compared to Man)"
params = {'q': song_title}
response = requests.get(search_url, params=params, headers=headers)


api = genius.Genius(access_token)
song_lyrics_milo = api.search_artist(artist_name='<NAME>')
song_lyrics = api.search_artist(artist_name='<NAME>')
song_lyrics.songs[0].lyrics
i = len(songs)

lyric_dict = dict(
    artist=[], 
    song=[], 
    lyrics=[], 
    year=[],
)

#for i in range(i):
for i, song in enumerate(songs):
    song_lyrics = api.search_song(song_title=song[1], artist_name=song[0])
    
    if song_lyrics:
        lyric_dict['year'].append(song_lyrics.year)
        lyric_dict['artist'].append(song_lyrics.artist)
        lyric_dict['lyrics'].append(song_lyrics.lyrics)
        lyric_dict['song'].append(song_lyrics.title)
    elif i > 5:
        break
    else:
        continue

song_lyric_count = len(lyric_dict['artist'])
lyrics_coverage = (song_lyric_count / i)
print("Lyrics were found for {:.2%} ({}) of saved songs.".format(lyrics_coverage, song_lyric_count))
lyric_df = pd.DataFrame(lyric_dict)
pd.to_pickle(lyric_df, 'saved_song_lyrics.pkl')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13377324535092983, 'fraction_numerical': 0.002999400119976005, 'mean_word_length': 5.043478260869565, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '122683', 'license': 'FTL', 'n_tokens_mistral': 631, 'n_tokens_neox': 604, 'n_words': 127, 'path': 'notebooks/saved_song_lyrics.ipynb', 'repo_name': 'colinspear/music-dashboard', 'size': '1742'}