Let's write an application which uses the Musixmatch API https://developer.musixmatch.com/ to obtain lyrics to a song.
We then run sentiment analysis over the song lyrics using the Azure Text Analytics service from the lab, or the Text-Processing API from the examples.
The basic gist of the application will be:
You should try to implement the following functions below. I suggest taking a bottom-up problem solving approach, first writing the function, testing it, and then finally using them in the main program. Remember good functions should do one thing well and have data inputs and data outputs through the return statement. They should be immutable, meaning the function does not change data but instead it returns the data back to the caller.
Once you implement the functions, implement your main program. Then implement any error handling.
In [48]:
import requests
def sentiment (text):
'''
returns the sentiment of the given text. up to you as to whether it returns just 'pos', 'neg', 'neutral' or more information
'''
key = "YOUR-KEY-HERE"
endpoint = "https://ist256-text-analytics.cognitiveservices.azure.com/"
url = f'{endpoint}text/analytics/v3.0-preview.1/sentiment'
# TODO: Write code here
def find_song(song_title, song_artist):
'''
get the closest matching song to title and artist using the track.search api call
return the first track
'''
# todo: implement here
def get_lyrics(track_id):
'''
get the closest matching song to title and artist using the track.lyrics.get api call
return the lyrics as text string
'''
# todo: implement here
# MAIN
In [ ]:
# RUN THIS CODE CELL TO TURN IN YOUR WORK!
from ist256.submission import Submission
Submission().submit()