Skip to content

Instantly share code, notes, and snippets.

@krclark
Created October 28, 2016 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krclark/fa5fa2ce6198930d7b3200043daf1ab8 to your computer and use it in GitHub Desktop.
Save krclark/fa5fa2ce6198930d7b3200043daf1ab8 to your computer and use it in GitHub Desktop.
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