Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Peacekeeping PEP-8 forces. #104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
19 changes: 6 additions & 13 deletions nba_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,14 @@ def _api_scrape(json_inp, ndx):
else:
A dictionary of both headers and values from the page
"""

try:
headers = json_inp['resultSets'][ndx]['headers']
values = json_inp['resultSets'][ndx]['rowSet']
headers = json_inp.get('resultSets', 'resultSet')[ndx]['headers']
values = json_inp.get('resultSets', 'resultSet')[ndx]['rowSet']
except KeyError:
# This is so ugly but this is what you get when your data comes out
# in not a standard format
try:
headers = json_inp['resultSet'][ndx]['headers']
values = json_inp['resultSet'][ndx]['rowSet']
except KeyError:
# Added for results that only include one set (ex. LeagueLeaders)
headers = json_inp['resultSet']['headers']
values = json_inp['resultSet']['rowSet']
# Added for results that only include one set (ex. LeagueLeaders)
headers = json_inp['resultSet']['headers']
values = json_inp['resultSet']['rowSet']

if HAS_PANDAS:
return DataFrame(values, columns=headers)
else:
Expand All @@ -85,7 +79,6 @@ def _get_json(endpoint, params, referer='scores'):
h['referer'] = 'http://stats.nba.com/{ref}/'.format(ref=referer)
_get = get(BASE_URL.format(endpoint=endpoint), params=params,
headers=h)
# print _get.url
_get.raise_for_status()
return _get.json()

Expand Down
15 changes: 10 additions & 5 deletions nba_py/constants.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from datetime import datetime

_curr_year = datetime.now().year
if datetime.now().month > 6:
CURRENT_SEASON = str(_curr_year) + "-" + str(_curr_year + 1)[2:]
else:
CURRENT_SEASON = str(_curr_year - 1) + "-" + str(_curr_year)[2:]

def set_current_season():
curr_year = datetime.now().year
current_season = '{}-{}'.format(curr_year - 1, str(curr_year)[2:])
if datetime.now().month > 6:
current_season = '{}-{}'.format(curr_year, str(curr_year+1)[2:])
return current_season


CURRENT_SEASON = set_current_season()

TEAMS = {
'ATL': {
Expand Down
1 change: 1 addition & 0 deletions tests/test_nba_py.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nba_py


def test():
assert nba_py.Scoreboard(month=2, day=21, year=2015)
22 changes: 10 additions & 12 deletions tests/test_nba_py_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@
except ImportError:
pass

class TestPlayerSpeedDistanceTracking:

class TestPlayerSpeedDistanceTracking:
def test_overall(self):
speed = league.PlayerSpeedDistanceTracking(date_from='03/05/2016',
date_to='03/05/2016', season="2015-16")
assert speed
overall = speed.overall()
assert overall
iter = filter(lambda d: d['PLAYER_NAME'] == 'Derrick Rose', overall)
stats = next(iter)
iterator = filter(lambda d: d['PLAYER_NAME'] == 'Derrick Rose', overall)
stats = next(iterator)
assert stats
assert stats['GP'] == 1
assert stats['MIN'] == 29.25
assert stats['DIST_MILES'] == 2.24
assert stats['DIST_FEET'] == 11827.0
assert stats['DIST_MILES_OFF'] == 1.29
assert stats['DIST_MILES_DEF'] == 0.95
assert stats['AVG_SPEED'] == 4.52
assert stats['AVG_SPEED_OFF'] == 4.94
assert stats['AVG_SPEED_DEF'] == 4.42
assertions = {
stats['GP']: 1, stats['MIN']: 29.25, stats['DIST_MILES']: 2.24,
stats['DIST_FEET']: 11827.0, stats['DIST_MILES_OFF']: 1.29, stats['DIST_MILES_DEF']: 0.95,
stats['AVG_SPEED']: 4.52, stats['AVG_SPEED_OFF']: 4.94, stats['AVG_SPEED_DEF']: 4.42
}
for assertion in assertions:
assert assertion == assertions[assertion]
1 change: 1 addition & 0 deletions tests/test_nba_py_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from nba_py.player import get_player
from nba_py.constants import TEAMS


def test():
team_id = TEAMS['ATL']['id']
player_id = get_player('Lebron', 'James')
Expand Down