From 662f97e8cd1efec21ab7ece7cfcb3edf41966f54 Mon Sep 17 00:00:00 2001 From: insightpeter Date: Thu, 1 Dec 2016 15:22:15 +0000 Subject: [PATCH 1/4] Added method _get_schedule with endpoint from data.nba.com --- nba_py/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nba_py/__init__.py b/nba_py/__init__.py index 87f438d..a0e248e 100644 --- a/nba_py/__init__.py +++ b/nba_py/__init__.py @@ -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 From 4fd0cfaf993391f77d40b53c2dc7c2d9b0c2fa7a Mon Sep 17 00:00:00 2001 From: insightpeter Date: Thu, 1 Dec 2016 15:23:49 +0000 Subject: [PATCH 2/4] Added class FullSchedule to get large json files of all games past/future --- nba_py/team.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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() From 038c67cf9ca34282e1bfb30a9fa3c0b0cedd22d1 Mon Sep 17 00:00:00 2001 From: insightpeter Date: Thu, 1 Dec 2016 15:28:15 +0000 Subject: [PATCH 3/4] Added an example of Dallas games in December. --- examples/example_team.py | 7 +++++++ 1 file changed, 7 insertions(+) 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 From 6041dd5327d6617f18826921d26998ecbfff8875 Mon Sep 17 00:00:00 2001 From: peter roche Date: Fri, 27 Jan 2017 16:24:04 +0000 Subject: [PATCH 4/4] Changed HAS_PANDAS to False so the data returned is in JSON --- nba_py/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nba_py/__init__.py b/nba_py/__init__.py index a0e248e..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: