def related_display(artist): try: conn = sqlite3.connect(DBNAME) cur = conn.cursor() except Error as e: print(e) #request data and log it in the DB, if it doesn't already exist artist_result = model.search_artists(artist) #get name for query matching artist_name = artist_result[1] artist_name_query = (artist_result[1], ) model.get_others_in_genre(artist_name) #Top five related artists that link to the most recent artist added to the artists table (this table contains all artists the user searched) statement = """ SELECT r.Name, r.URL FROM RelatedArtists as r JOIN Artists AS a ON r.Searched_Artist_Id = a.Id WHERE a.Name = ? LIMIT 5 """ pull = cur.execute(statement, artist_name_query).fetchall() related_dict = {} for row in pull: related_dict[row[0]] = row[1] return related_dict conn.close()
def artist_display(artist): try: conn = sqlite3.connect(DBNAME) cur = conn.cursor() except Error as e: print(e) #request data and log it in the DB artist_result = model.search_artists(artist) #get id for query matching artist_id = (artist_result[0], ) #Top five related artists that link to the most recent artist added to the artists table (this table contains all artists the user searched) statement = """ SELECT Name, Image FROM Artists WHERE Spotify_Id = ? ORDER BY Id DESC LIMIT 1 """ pull = cur.execute(statement, artist_id).fetchall() artist_list = [] for row in pull: artist_list.append(row[0]) artist_list.append(row[1]) return artist_list conn.close()
def track_display(artist): try: conn = sqlite3.connect(DBNAME) cur = conn.cursor() except Error as e: print(e) #get name for query matching artist_result = model.search_artists(artist) artist_name = artist_result[1] artist_name_query = (artist_result[1], ) #Make the reuest and log to db model.get_top_tracks(artist) #Top five tracks that link to the most recent artist added to the artists table (this table contains all artists the user searched) statement = """ SELECT t.Name, t.URL FROM Tracks as t JOIN Artists AS a ON t.Searched_Artist_Id = a.Id WHERE a.Name = ? LIMIT 5 """ pull = cur.execute(statement, artist_name_query).fetchall() track_dict = {} for row in pull: #Only top 5 track_dict[row[0]] = row[1] return track_dict conn.close()
def article_display(artist): try: conn = sqlite3.connect(DBNAME) cur = conn.cursor() except Error as e: print(e) #get name for query matching artist_result = model.search_artists(artist) artist_name = artist_result[1] artist_name_query = (artist_result[1], ) #Make the request and log it to the DB model.get_headlines(artist) #Top five articles that link to the most recent artist added to the artists table (this table contains all artists the user searched) statement = """ SELECT h.Title, h.URL, h.Source, h.PublishedAt FROM Articles as h JOIN Artists AS a ON h.Searched_Artist_Id = a.Id WHERE a.Name = ? LIMIT 5 """ pull = cur.execute(statement, artist_name_query).fetchall() article_dict = {} for row in pull: #Only top 5 article_dict[row[0]] = [row[1], row[2], row[3]] return article_dict
class TestCalls(unittest.TestCase): search1 = model.search_artists("Amy Winehouse") search2 = model.search_artists("Danny Brown") search3 = model.get_others_in_genre("Amy Winehouse") search4 = model.get_top_tracks("Janis Joplin") search5 = model.get_headlines("Danny Brown") search6 = model.get_wiki_page("Frank Sinatra") def testArtistSearch(self): #successful artist name self.assertEqual(TestCalls.search1[1], "Amy Winehouse") #successful artist id self.assertEqual(TestCalls.search1[0],"6Q192DXotxtaysaqNPy5yR") def testRelated(self): #successful related artist count self.assertEqual(len(TestCalls.search3),20) #succesful related artist accuracy self.assertEqual(TestCalls.search3[3].name,"Macy Gray") def testTop(self): #successful top track count self.assertEqual(len(TestCalls.search4),10) #successful top track self.assertEqual(TestCalls.search4[0].name,"Me and Bobby McGee") #successful top track order self.assertEqual(TestCalls.search4[2].name,"Maybe") def testHeadline(self): #successful results self.assertEqual(len(TestCalls.search5),20) #successful source self.assertEqual(TestCalls.search5[0].source,"The New York Times") #successful description self.assertEqual(TestCalls.search5[1].description,"Here’s what you need to know to start your day.") #successful title self.assertEqual(TestCalls.search5[4].title,"Six Nations: James Haskell & Joe Marler in England squad v Scotland") def testOverview(self): #successful results self.assertTrue(len(TestCalls.search6) > 20) #Wiki result is greater than 20 characters #successful overview self.assertEqual(TestCalls.search6[-26:],"before his death in 1998.\n")