Exemplo n.º 1
0
 def __parse_game_info(self):
     """ Set up the game info dictionary and add it to self.json """
     soup = self.soups["game_info"]
     # Find each row of the table
     rows = soup.find_all("tr")
     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 value
             tmp_key = cols[0].get_text(strip=True)
             tmp_value = cols[1].get_text(strip=True)
             if tmp_key == "Stadium":
                 (stad, dome) = convert_stadium(tmp_value)
                 self.json["venue"]["stadium"] = stad
                 self.json["venue"]["dome"] = dome
             elif tmp_key == "Start Time":
                 self.json["datetime"]["start time"] = convert_time(tmp_value)
             elif tmp_key == "Surface":
                 self.json["venue"]["surface"] = tmp_value
             elif tmp_key == "Duration":
                 self.json["datetime"]["duration"] = convert_duration(tmp_value)
             elif tmp_key == "Attendance":
                 # We need to replace commas for int to work
                 self.json["venue"]["attendance"] = int(tmp_value.replace(',', ''))
             elif tmp_key == "Weather":
                 self.json["weather"] = convert_weather(tmp_value)
             elif tmp_key == "Vegas Line":
                 (team_code, line) = convert_vegas_line(tmp_value)
                 self.json["betting"]["winner"] = team_code
                 self.json["betting"]["speard"] = line
             elif tmp_key == "Over/Under":
                 self.json["betting"]["over under"] = convert_overunder(tmp_value)
 def test_convert_weather(self):
     # Successful
     self.assertEqual(
             convert_weather("13 degrees, relative humidity 62%, wind 8 mph"),
             {"temperature": 13, "relative humidity": 0.62, "wind speed": 8, "wind chill": None}
             )
     self.assertEqual(
             convert_weather("35 degrees, relative humidity 59%, wind 10 mph, wind chill 27"),
             {"temperature": 35, "relative humidity": 0.59, "wind speed": 10, "wind chill": 27}
             )
     self.assertEqual(
             convert_weather("72 degrees, no wind"),
             {"temperature": 72, "relative humidity": None, "wind speed": 0, "wind chill": None}
             )
     self.assertEqual(
             convert_weather("28 degrees, wind 1 mph"),
             {"temperature": 28, "relative humidity": None, "wind speed": 1, "wind chill": None}
             )
     # Failure returns dictionary full of None, or a ValueError
     self.assertEqual(convert_weather("I have no idea what degree to get!"), None)
     self.assertRaises(ValueError, convert_weather, "twenty-eight degrees, wind five mph")
 def test_convert_weather(self):
     # Successful
     self.assertEqual(
             convert_weather("13 degrees, relative humidity 62%, wind 8 mph"),
             {"temperature": 13, "relative humidity": 0.62, "wind speed": 8, "wind chill": None}
             )
     self.assertEqual(
             convert_weather("35 degrees, relative humidity 59%, wind 10 mph, wind chill 27"),
             {"temperature": 35, "relative humidity": 0.59, "wind speed": 10, "wind chill": 27}
             )
     self.assertEqual(
             convert_weather("72 degrees, no wind"),
             {"temperature": 72, "relative humidity": None, "wind speed": 0, "wind chill": None}
             )
     self.assertEqual(
             convert_weather("28 degrees, wind 1 mph"),
             {"temperature": 28, "relative humidity": None, "wind speed": 1, "wind chill": None}
             )
     # Failure returns None
     self.assertEqual(
             convert_weather("I have no idea what degree to get!"), None)