Exemplo n.º 1
0
 def __parse_team_stats(self):
     """ Set up the team stats dictionaries and add it to self.json """
     soup = self.soups["team_stats"]
     # Find each row of the table
     rows = soup.find_all("tr")
     home_dict = self.json["team stats"]["home"]
     away_dict = self.json["team stats"]["away"]
     for row in rows:
         # Find each column of the table
         cols = row.find_all("td")
         if cols:  # This if removes the header
             # Extract the key and both the home and away team values
             key = cols[0].get_text(strip=True)
             tmp_away = cols[1].get_text(strip=True)
             tmp_home = cols[2].get_text(strip=True)
             if key == "First downs":
                 away_dict["first downs"] = int(tmp_away)
                 home_dict["first downs"] = int(tmp_home)
             elif key == "Rush-yards-TDs":
                 away_dict["rush"] = convert_rush_info(tmp_away)
                 home_dict["rush"] = convert_rush_info(tmp_home)
             elif key == "Comp-Att-Yd-TD-INT":
                 away_dict["pass"] = convert_pass_info(tmp_away)
                 home_dict["pass"] = convert_pass_info(tmp_home)
             elif key == "Sacked-yards":
                 away_dict["sacks"] = convert_sack_info(tmp_away)
                 home_dict["sacks"] = convert_sack_info(tmp_home)
             elif key == "Fumbles-lost":
                 away_dict["fumbles"] = convert_fumble_info(tmp_away)
                 home_dict["fumbles"] = convert_fumble_info(tmp_home)
             elif key == "Penalties-yards":
                 away_dict["penalties"] = convert_penalty_info(tmp_away)
                 home_dict["penalties"] = convert_penalty_info(tmp_home)
 def test_convert_penalty_info(self):
     # Successful
     self.assertEqual(convert_penalty_info("8-56"), {"plays": 8, "yards": -56})
     # Failure returns None
     self.assertEqual(convert_fumble_info("8 56"), None)
     self.assertEqual(convert_fumble_info("A-56"), None)
     self.assertEqual(convert_fumble_info("8-A"), None)
 def test_convert_fumble_info(self):
     # Successful
     self.assertEqual(convert_fumble_info("2-1"), {"plays": 2, "lost": 1})
     # Failure returns None
     self.assertEqual(convert_fumble_info("2 1"), None)
     self.assertEqual(convert_fumble_info("A-1"), None)
     self.assertEqual(convert_fumble_info("2-A"), None)
 def test_convert_fumble_info(self):
     # Successful
     self.assertEqual(convert_fumble_info("2-1"), {"plays": 2, "lost": 1})
     # Failure raises ValueError
     self.assertRaises(ValueError, convert_fumble_info, "2 1")
     self.assertRaises(ValueError, convert_fumble_info, "2-A")
     self.assertRaises(ValueError, convert_fumble_info, "A-2")