Module Expr Str Import alias Import alias Import alias Import alias ImportFrom alias Import alias Assign NameStore AttributeLoad AttributeLoad NameLoad attr attr Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults NameLoad NameLoad body Expr Str Assign NameStore SubscriptLoad Call AttributeLoad NameLoad attr NameLoad NameLoad Index Num If CompareLt NameLoad NameLoad body Return ListLoad Assign NameStore Call AttributeLoad NameLoad attr If CompareGt NameLoad AttributeLoad NameLoad attr body Return ListLoad orelse If BoolOpAnd CompareGtE NameLoad AttributeLoad NameLoad attr CompareGt NameLoad AttributeLoad NameLoad attr body Return ListLoad orelse If BoolOpAnd CompareGtE NameLoad AttributeLoad NameLoad attr CompareGtE NameLoad AttributeLoad NameLoad attr CompareGt NameLoad AttributeLoad NameLoad attr body Return ListLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad NameLoad keyword NameLoad keyword NameLoad Assign NameStore ListComp Call AttributeLoad AttributeLoad NameLoad attr attr SubscriptLoad NameLoad Index NameLoad comprehension NameStore NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults NameLoad NameLoad NameLoad NameLoad body Expr Str If CompareEq NameLoad NameLoad body Assign NameStore Call NameLoad Call NameLoad Num Num If CompareEq NameLoad NameLoad body Assign NameStore Call NameLoad Call NameLoad Num Num Assign NameStore ListLoad If UnaryOpNot Call NameLoad NameLoad NameLoad body Assign NameStore ListLoad NameLoad If UnaryOpNot Call NameLoad NameLoad NameLoad body Assign NameStore ListLoad NameLoad If UnaryOpNot Call NameLoad NameLoad NameLoad body Assign NameStore ListLoad NameLoad For NameStore NameLoad body For NameStore NameLoad body Assign NameStore SubscriptLoad Call AttributeLoad NameLoad attr NameLoad NameLoad Index Num For NameStore NameLoad body If CompareGtE NameLoad NameLoad body Assign NameStore Call NameLoad NameLoad NameLoad NameLoad keyword NameLoad keyword NameLoad If CompareNotEq NameLoad ListLoad body Expr Call AttributeLoad NameLoad attr NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore ListComp NameLoad comprehension NameStore NameLoad comprehension NameStore NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Dict Str Str Str Str ListLoad ListLoad ListLoad ListLoad For NameStore NameLoad body For NameStore SubscriptLoad NameLoad Index NameLoad body If BoolOpOr CompareEq NameLoad Str CompareEq NameLoad Str body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad orelse If BoolOpOr CompareEq NameLoad Str CompareEq NameLoad Str body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Expr Call AttributeLoad SubscriptLoad NameLoad Index NameLoad attr NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore DictComp NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr SubscriptLoad NameLoad Index NameLoad comprehension NameStore NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore ListComp NameLoad comprehension NameStore NameLoad comprehension NameStore SubscriptLoad NameLoad Index NameLoad Return NameLoad decorator_list
N/A N/A mlbgame is a Python API to retrieve and read MLB GameDay XML data.
mlbgame works with real time data, getting information as games are being played.

mlbgame uses the same data that MLB GameDay uses,
and therefore is updated as soon as something happens in a game.

mlbgame currently comes pre-loaded with scoreboard information for every game
from 2012 to the end of the 2015 season,
but will be updated regularly during the season.
Therefore, accessing this data does not actually make a request to mlb.com.

If you try to get data from a game that is not cached,
mlbgame will download the data from mlb.com.

There are a lot of extra data for individual games that do not come
pre-installed with mlbgame, but can be installed by running update scripts
shown below. This data is not included becuase it takes up too much space, 
and therefore a request to mlb.com every time is a better option 
because not everyone will want to access this data.

mlbgame [documentation](http://zachpanz88.github.io/mlbgame)

mlbgame on [Github](https://github.com/zachpanz88/mlbgame) (Source Code)

If you have a question or need help, the quickest way to get a response 
is to file an issue on the [Github issue tracker](https://github.com/zachpanz88/mlbgame/issues/new)

mlbgame's submodules (except for `statmap`) should not really be used other than as 
used by the main functions of the package (in `__init__.py`).

Installation
------------

mlbgame is in the [Python Package Index (PyPI)](http://pypi.python.org/pypi/mlbgame/).
Installing with `pip` is recommended for all systems.

mlbgame can be installed by running:

    pip install mlbgame

Alternatively, the latest release of mlbgame can be downloaded as a 
[zip](https://github.com/zachpanz88/mlbgame/archive/master.zip) or [tarball](https://github.com/zachpanz88/mlbgame/archive/master.tar.gz). 
If you do not install with `pip`, you must also install [lxml](http://lxml.de/) for mlbgame to work.

Updating the Game Database
--------------------------

Since games happen every day, new game data exists that is not stored on disk from the original install.
The database can be updated by running the following command:

    mlbgame-update

There are some optional arguments that will cache extra data that is not included with the original install.
This extra data may take up a lot of disk space, so only cache if you really need it (it will make processes much faster).
If this data is not cached, mlbgame will make a request to mlb.com every time you try to access the data.

    usage: mlbgame-update <arguments>
    
    Arguments:
    --help (-h): display this help menu
    --hide: hides output from update script
    --more (-m): saves the box scores and individual game stats from every game
    --start (-s) <MM-DD-YYYY>: date to start updating from (default: 01-01-2012)
    --end (-e) <MM-DD-YYYY>: date to update until (default: current day)

Use of mlbgame must follow the terms stated in the 
[license](https://raw.githubusercontent.com/zachpanz88/mlbgame/master/LICENSE) 
and on [mlb.com](http://gd2.mlb.com/components/copyright.txt>).

Examples
--------

Here is a quick teaser to find the scores of all home Mets games for the month of June, 2015:

    #!python
    from __future__ import print_function
    import mlbgame
    
    month = mlbgame.games(2015, 6, home="Mets")
    games = mlbgame.combine_games(month)
    for game in games:
        print(game)
    
And the output is:

    Giants (5) at Mets (0)
    Giants (8) at Mets (5)
    Giants (4) at Mets (5)
    Braves (3) at Mets (5)
    Braves (5) at Mets (3)
    Braves (8) at Mets (10)
    Blue Jays (3) at Mets (4)
    Blue Jays (2) at Mets (3)
    Reds (1) at Mets (2)
    Reds (1) at Mets (2)
    Reds (1) at Mets (2)
    Reds (2) at Mets (7)
    Cubs (1) at Mets (0)

Maybe you want to know the pitchers for the Royals game on April 30th, 2015:

    #!python
    from __future__ import print_function
    import mlbgame
    
    day = mlbgame.day(2015, 4, 12, home="Royals", away="Royals")
    game = day[0]
    output = "Winning pitcher: %s (%s) - Losing Pitcher: %s (%s)"
    print(output % (game.w_pitcher, game.w_team, game.l_pitcher, game.l_team))

And the output is:

    Winning pitcher: Y. Ventura (Royals) - Losing Pitcher: C. Wilson (Angels)

Finding stats for the Mets batters
in the final game of the 2015 World Series
can also be done:

    #!python
    from __future__ import print_function
    import mlbgame
    
    game = mlbgame.day(2015, 11, 1, home="Mets")[0]
    stats = mlbgame.player_stats(game.game_id)
    for player in stats['home_batting']:
        print(player)

And the output is:

    Curtis Granderson - 1 for 4 with 1 RBI and 1 Home Runs
    David Wright - 1 for 5
    Daniel Murphy - 0 for 3
    Yoenis Cespedes - 0 for 3
    Juan Lagares - 0 for 2
    Lucas Duda - 0 for 2 with 1 RBI
    Travis d'Arnaud - 0 for 5
    Michael Conforto - 2 for 5
    Wilmer Flores - 0 for 4
    Matt Harvey - 0 for 3
    Jeurys Familia - 0 for 0
    Kelly Johnson - 0 for 1
    Jon Niese - 0 for 0
    Addison Reed - 0 for 0
    Bartolo Colon - 0 for 0

Contributors
------------
    
[Zach Panzarino](https://github.com/zachpanz88) (Creator, Maintainer)

[Robert Simione](https://github.com/robertsimione) (Python 3 Compatibility)
 N/A sys N/A mlbgame.game N/A mlbgame.stats N/A calendar datetime date N/A mlbgame.version N/A VERSION N/A N/A mlbgame version __version__ N/A Installed version of mlbgame. day N/A N/A year month day home away N/A None None N/A N/A Return a list of games for a certain day.
    
    If the home and away team are the same, it will return the game(s) for that team.
     N/A daysinmonth N/A N/A N/A calendar monthrange year month N/A 1 N/A N/A daysinmonth day N/A N/A N/A N/A today N/A N/A date today N/A N/A year N/A today year N/A N/A N/A N/A N/A N/A N/A year N/A today year N/A month N/A today month N/A N/A N/A N/A N/A N/A N/A year N/A today year N/A month N/A today month N/A day N/A today day N/A N/A N/A N/A data N/A N/A N/A mlbgame game scoreboard year month day home home away away N/A results N/A N/A N/A N/A mlbgame game GameScoreboard N/A data N/A x N/A x data N/A results N/A games N/A N/A years months days home away N/A None None None None N/A N/A Return a list of lists of games for multiple days.
    
    If home and away are the same team, it will return all games for that team.
     N/A N/A months None N/A N/A months N/A list N/A range 1 13 N/A N/A days None N/A N/A days N/A list N/A range 1 32 N/A results N/A N/A N/A N/A isinstance years list N/A N/A years N/A years N/A N/A N/A isinstance months list N/A N/A months N/A months N/A N/A N/A isinstance days list N/A N/A days N/A days N/A i years N/A N/A y months N/A N/A daysinmonth N/A N/A N/A calendar monthrange i y N/A 1 N/A x days N/A N/A N/A daysinmonth x N/A N/A game N/A day i y x home home away away N/A N/A game N/A N/A N/A N/A N/A results append game N/A results N/A box_score N/A N/A game_id N/A N/A N/A Return box score for game matching the game id. N/A data N/A N/A N/A mlbgame game box_score game_id N/A obj N/A N/A N/A mlbgame game GameBoxScore data N/A obj N/A combine_games N/A N/A games N/A N/A N/A Combines games from multiple days into a single list. N/A output N/A y N/A x games N/A y x N/A output N/A player_stats N/A N/A game_id N/A N/A N/A Return dictionary of player stats for game matching the game id. N/A data N/A N/A N/A mlbgame stats player_stats game_id N/A output N/A home_pitching away_pitching home_batting away_batting N/A N/A N/A N/A N/A y data N/A N/A x N/A data N/A y N/A N/A N/A N/A y home_pitching N/A y away_pitching N/A N/A obj N/A N/A N/A mlbgame stats PitcherStats x N/A N/A N/A N/A y home_batting N/A y away_batting N/A N/A obj N/A N/A N/A mlbgame stats BatterStats x N/A N/A N/A N/A output N/A y append obj N/A output N/A team_stats N/A N/A game_id N/A N/A N/A Return dictionary of team stats for game matching the game id. N/A data N/A N/A N/A mlbgame stats team_stats game_id N/A output N/A x N/A N/A N/A mlbgame stats TeamStats N/A data N/A x N/A x data N/A output N/A combine_stats N/A N/A stats N/A N/A N/A Combines player stat objects from a game into a single list. N/A output N/A y N/A x stats N/A y N/A stats N/A x N/A output N/A