diff --git a/examples/example_team.py b/examples/example_team.py index cb31999..4e38e92 100644 --- a/examples/example_team.py +++ b/examples/example_team.py @@ -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']) \ No newline at end of file diff --git a/nba_py/__init__.py b/nba_py/__init__.py index 87f438d..0dbfb92 100644 --- a/nba_py/__init__.py +++ b/nba_py/__init__.py @@ -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: @@ -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'), @@ -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 diff --git a/nba_py/team.py b/nba_py/team.py index 1ff4121..bfd2ee5 100644 --- a/nba_py/team.py +++ b/nba_py/team.py @@ -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 * @@ -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()