def test_convert_title_teams(self): # Successful self.assertEqual( convert_title_teams("St. Louis Rams at Seattle Seahawks"), ("SEA", "STL") ) self.assertEqual( convert_title_teams("Baltimore Ravens vs. New York Giants"), ("NYG", "BAL") ) # Failure self.assertRaises( KeyError, convert_title_teams, "Rams at Seahawks" ) self.assertRaises( ValueError, convert_title_teams, "St. Louis Rams @ Seattle Seahawks" )
def __parse_title(self): """ Parse the title tag from the HTML. This sets the two teams and the date.""" soup = self.soups["title"] text = soup.find("title").get_text(strip=True) teams = text.split('-')[0] fulldate = text.split('-')[1] # Parse teams to codes (home, away) = convert_title_teams(teams) self.json["home team"] = home self.json["away team"] = away # Parse time self.json["datetime"]["date"] = convert_title_date(fulldate)