Beispiel #1
0
def get_todays_games():
    """
    Get the game's going on today. 
    
    Parameters:
    -----------
    
    None
    
    
    Returns 
    -------
    
    matchups : arr
        array of all the matchups today. Note I skip the first element since it just denotes road, or home which is known
        now. 
        
        
    
    """

    today = datetime.now()
    day = today.day
    month = today.month
    year = today.year

    ex = Scoreboard(month=month, day=day, year=year)
    games = ex.game_header()['GAMECODE']
    matchups = []
    matchups.append(['road', 'home'])
    for game in games:
        away_team = game[-6:-3]
        home_team = game[-3:]

        if away_team == 'BKN':
            away_team = 'BRK'
        if home_team == 'BKN':
            home_team = 'BRK'

        matchups.append([away_team, home_team])

    return matchups[1:]
Beispiel #2
0
from nba_py import Scoreboard
from datetime import date
from datetime import timedelta
from time import sleep
import json

sd = date(2008, 5, 16)  # (1980,11,17)
ed = date.today()  # (2008,1,1)
league_id = '00'
day_offset = 0

gameids = set()


def daterange(start_date, end_date):
    for n in range(int((end_date - start_date).days)):
        yield start_date + timedelta(n)


file = open("../csv/game_ids.csv", 'a')
for date in daterange(sd, ed):
    try:
        sb = Scoreboard(date.month, date.day, date.year, league_id, day_offset)
        for game in sb.game_header():
            file.write(game['GAME_ID'] + '\n')
        print(date.strftime("%Y-%m-%d") + " successful")
        sleep(2)
    except Exception as exception:
        print(exception)

file.close()
Beispiel #3
0
from nba_py import constants
from nba_py import team
from nba_py import Scoreboard
import requests
import requests_cache
from datetime import date
pd.set_option('display.max_columns', None)

# Get todays date for input to nba_py module
today = str(date.today())
year, month, day = today.split("-")
year, month, day = int(year), int(month), int(day)

# Returns dataframe about todays NBA games, contains the ID's of the teams that are playing
games_df = Scoreboard(month=month, day=day, year=year)
games_df = games_df.game_header()

games = []

# Process dataframe and returns games which is a list of games being played
for index, row in games_df.iterrows():
    game = []
    # Get team ID and convert to team name
    road_team = row['VISITOR_TEAM_ID']
    road_team = team.TeamSummary(road_team)
    road_team = road_team.info()
    road_team = road_team['TEAM_NAME'].values[0]
    game.append(road_team)
    home_team = row['HOME_TEAM_ID']
    home_team = team.TeamSummary(home_team)
    home_team = home_team.info()