Closed idohi closed 5 years ago
I'm actually doing a similar thing right now, so here's what I found:
The way I go about this is:
(1) Get team ids from nba_py.TeamList and filter out the ones that are no longer active (the list there will contain historical NBA teams too).
(2) loop through team ids returned from (1) with nba_py.teams.TeamGameLogs to get the game details, e.g:
nba_py.teams.TeamGameLogs("1610612749", "2017-18").json
will get you games from 2017-18 for Milwaukee.
(3) You can use the games details from (2) to make further calls to nba_py.games, since you will have all the game ids you need.
EDITED Make sure you have requests-cache installed. Otherwise you won't be able to pull in a whole season's worth of data for all teams. With requests-cache it works like a charm.
I tried to extract teams with nba_py.team.TeamList()
but some how it is stuck (request-cache is installed).
I tried to extract teams with
nba_py.team.TeamList()
but some how it is stuck (request-cache is installed).
Are you able to get data from other nba_py modules?
Following 2 examples: one when I get the data and the other when I don't.
[When I get data]
from nba_py.constants import TEAMS
team_id = TEAMS['ATL']['id']
(team_id: '1610612737')
[When I don't get data]
from nba_py.player import get_player
player_id = get_player('Lebron', 'James')
Maybe its a memory issue, maybe I don't use requests-cache properly.
There 2 things to note here:
nba_py.constants import TEAMS
you're doing in example nr 1 doesn't actually fetch any data from nba.com. Instead, it reads the _teamid property from a dictionary stored in the nba_py module's own files, i.e. from your own hard drive. That's why you can retrieve it without any hassle.get_player = player.get_player("Lebron", last_name="James")
print(get_player)
(I didn't check that code specifically, as I'm not fetching player data myself, but here is a good resource for nba_py method calls in general: https://www.slothparadise.com/nba_py-documentation/)
If you try to run the code I pasted here it should get you Lebron's player id. If it won't, you should at least get an error that will be helpful in further troubleshooting.
It works! Thanks for the assist. I installed the package following the instructions in the link you have sent with a small change. (https://www.slothparadise.com/nba_py-documentation/)
pip install .
Now, the package is working properly.
I am trying to get all games details in a specific year. The classes in "nba_py.game" module required "game_id", but I need details about all the games. Help will be greatly appreciated.