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")
def feed(): headlines = get_headlines() return render_template('feed.html', headlines=headlines)