Skip to content

Instantly share code, notes, and snippets.

@krclark krclark/lyrics.py Secret
Created Oct 28, 2016

Embed
What would you like to do?
import unirest
import random
rappers = ["Tupac", "Lil Uzi Vert", "Lil Yachty", "21 Savage", "Schoolboy Q", "Ice Cube", "DMX", "Method Man", "Eminem", "Busta Rhymes",
"Gang Starr", "Immortal Technique", "A$AP Rocky", "Trick Daddy", "Jay-Z", "Snoop Dogg", "Dr Dre", "WuTang Clan", "Future",
"OG Maco", "OT Genasis", "The Notorious BIG", "50 Cent", "Nate Dogg", "Chief Keef", "Rae Sremmurd", "Fetty Wap", "Young Thug",
"Gucci Mane", "Rich Homie Quan", "Kodak Black", "Lil Wayne", "Rick Ross", "Birdman", "Tyler The Creator", "Nipsey Hussle", "YG",
"Tyga", "Soulja Boy"]
def lyrics(artist):
lyricarray = []
# These code snippets use an open-source library. http://unirest.io/python
try:
response = unirest.get("https://community-lyricsnmusic.p.mashape.com/songs?api_key=d221bf3e01b0d1a57e5a49449e6230&artist="+artist,
headers={
"X-Mashape-Key": "6wjG61ZSNGmsh7XMfqDAgiL7XHOwp1lcy7BjsnZCdhPEQlQ5q5",
"Accept": "application/json"
}
)
except:
#print("BROKE")
return 1;
thefile = open('lyrics_'+artist+'.txt', 'w+')
for i in response.body:
if type(i) == str:
#print("BROKE2")
return 1;
lyricarray.extend(i.get('snippet').split("\r\n"))
for j in lyricarray:
j = j.encode('ascii', 'ignore')
thefile.write("%s\n\n" % j)
thefile.close()
return 0;
def run():
for rapper in rappers:
k = lyrics(rapper)
if k == 1:
print("Failed on"+artist+"\n")
print("Success")
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.