Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.
Open
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
7 changes: 7 additions & 0 deletions examples/example_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@
print('Spurs stats vs Tyson Chandler (2010-11)')
print('On court: {}'.format(float(r_on['FG_PCT'])))
print('Off court: {}'.format(float(r_off['FG_PCT'])))

# print a list of all dallas games in December
fs = team.FullSchedule().info()
list_of_games = fs['lscd'][2]['mscd']['g'] # 0=Oct 1=Nov, 2=Dec...
for game in list_of_games:
if game['v']['tc'] == 'Dallas' or game['h']['tc'] == 'Dallas':
print(game['gdte'] + ' ' + game['v']['tc'] + ' ' + game['v']['s'] + ' @ ' + str(game['h']['tc']) + ' ' + game['h']['s'])
12 changes: 11 additions & 1 deletion nba_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from nba_py.constants import League
import os

HAS_PANDAS = True
HAS_PANDAS = False
try:
from pandas import DataFrame
except ImportError:
Expand All @@ -21,6 +21,7 @@
# Constants
TODAY = datetime.today()
BASE_URL = 'http://stats.nba.com/stats/{endpoint}'
SCHEDULE_URL = 'http://data.nba.com/data/10s/v2015/json/mobile_teams/nba/2016/league/00_full_schedule.json'
HEADERS = {'user-agent': ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/45.0.2454.101 Safari/537.36'),
Expand Down Expand Up @@ -86,6 +87,15 @@ def _get_json(endpoint, params, referer='scores'):
return _get.json()


def _get_schedule(referer='schedule'):
h = dict(HEADERS)
h['referer'] = 'http://stats.nba.com/{ref}/'.format(ref=referer)
_get = get(SCHEDULE_URL, headers=h)
# print _get.url
_get.raise_for_status()
return _get.json()


class Scoreboard:
""" A scoreboard for all games for a given day
Displays current games plus info for a given day
Expand Down
8 changes: 7 additions & 1 deletion nba_py/team.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nba_py import _api_scrape, _get_json
from nba_py import _api_scrape, _get_json, _get_schedule
from nba_py.constants import *


Expand Down Expand Up @@ -559,3 +559,9 @@ def shot_area_on_court(self):

def shot_area_off_court(self):
return _api_scrape(self.json, 8)


class FullSchedule:
@staticmethod
def info():
return _get_schedule()