Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attendance data to Overview class #70

Merged
merged 1 commit into from
Mar 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions mlbgame/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,24 +321,27 @@ def print_scoreboard(self):
def overview(game_id):
"""Gets the overview information for the game with matching id."""
# get data
data = mlbgame.data.get_overview(game_id)
overview = mlbgame.data.get_overview(game_id)
raw_box_score = mlbgame.data.get_raw_box_score(game_id)
# parse data
parsed = etree.parse(data)
root = parsed.getroot()
overview_root = etree.parse(overview).getroot()
raw_box_score_root = etree.parse(raw_box_score).getroot()
output = {}
# get overview attributes
for x in root.attrib:
output[x] = root.attrib[x]

for x in overview_root.attrib:
output[x] = overview_root.attrib[x]
# get attendance from raw box score
output['attendance'] = raw_box_score_root.attrib['attendance']

# Get probable starter attributes if they exist
home_pitcher_tree = root.find('home_probable_pitcher')
home_pitcher_tree = overview_root.find('home_probable_pitcher')
if home_pitcher_tree is not None:
output.update(build_namespaced_attributes(
'home_probable_pitcher', home_pitcher_tree))
else:
output.update(build_probable_starter_defaults('home'))

away_pitcher_tree = root.find('away_probable_pitcher')
away_pitcher_tree = overview_root.find('away_probable_pitcher')
if away_pitcher_tree is not None:
output.update(build_namespaced_attributes(
'away_probable_pitcher', away_pitcher_tree))
Expand Down Expand Up @@ -381,6 +384,7 @@ class Overview(mlbgame.object.Object):

Properties:
ampm
attendance
aw_lg_ampm
away_ampm
away_code
Expand Down
1 change: 1 addition & 0 deletions tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def test_box_score_empty(self):
def test_overview(self):
overview = mlbgame.overview('2016_08_02_nyamlb_nynmlb_1')
self.assertEqual(overview.ampm, 'PM')
self.assertEqual(overview.attendance, '42,819')
self.assertEqual(overview.aw_lg_ampm, 'PM')
self.assertEqual(overview.away_ampm, 'PM')
self.assertEqual(overview.away_code, 'nya')
Expand Down