Created
October 5, 2018 21:54
-
-
Save sleggett/17ffd360b1ad464552590e072bac4f48 to your computer and use it in GitHub Desktop.
nba_led_game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nba_api.stats.endpoints import* | |
class Game: | |
def __init__(self): | |
self.game_id = 123 | |
self.home_team_name = 'HoMeTeAm' | |
self.home_team_id = 123 | |
self.away_team_name = 'AwAyTeAm' | |
self.away_team_id = 123 | |
self.home_score = 0 | |
self.away_score = 0 | |
self.period = 'Q1' | |
self.remain_period_time = '0:00' | |
self.game_status_text = 'NoTlIvE' | |
self.game_status = 0 | |
def print_scoreboard(self): | |
print('{:10}'.format(self.home_team_name) + '{:>10}'.format(self.home_score) + '\n' + | |
'{:10}'.format(self.away_team_name) + '{:>10}'.format(self.away_score) + '\n' + | |
'{:10}'.format(self.game_status_text)) | |
def get_game_stats(self, df_game): | |
self.game_status_text = df_game['GAME_STATUS_TEXT'] | |
self.game_status = df_game['GAME_STATUS_ID'] | |
self.game_id = df_game['GAME_ID'] | |
self.home_team_id = df_game['HOME_TEAM_ID'] | |
self.away_team_id = df_game['VISITOR_TEAM_ID'] | |
self.period = df_game['LIVE_PERIOD'] | |
self.remain_period_time = df_game['LIVE_PC_TIME'] | |
self.get_team_names() | |
def get_team_names(self): | |
home_team_info = teamdetails.TeamDetails(self.home_team_id).team_history.get_data_frame() | |
if not home_team_info.empty: | |
self.home_team_name = home_team_info.iloc[0]['NICKNAME'] | |
away_team_info = teamdetails.TeamDetails(self.away_team_id).team_history.get_data_frame() | |
if not away_team_info.empty: | |
self.away_team_name = away_team_info.iloc[0]['NICKNAME'] | |
def get_live_stats(self): | |
#game_status_id has to be greater than 1 | |
if self.game_status > 1: | |
df_boxscore = boxscoresummaryv2.BoxScoreSummaryV2(self.game_id).line_score.get_data_frame() | |
if df_boxscore.iloc[0]['TEAM_ID'] == self.home_team_id: | |
self.home_score = df_boxscore.iloc[0]['PTS'] | |
self.away_score = df_boxscore.iloc[1]['PTS'] | |
else: | |
self.home_score = df_boxscore.iloc[1]['PTS'] | |
self.away_score = df_boxscore.iloc[0]['PTS'] | |
#print(df_boxscore) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment