def request_all_team_gamelogs(team_list): initial_inputs() data_category = 'team' for key in team_list: if season_name_type == "playoff": Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data(league=league_name, season=season_name_begin + season_name_type, feed="team_gamelogs", format=file_format, team=key) #can add more optional params manually else: Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data( league=league_name, season=season_name_begin + season_name_end + season_name_type, feed="team_gamelogs", format=file_format, team=key)
def request_daily(): initial_inputs() data_type = [ "daily_game_schedule", "daily_player_stats", "scoreboard", "roster_player" ] data_category = input( "Enter 'all' for daily_game_schedule, daily_player_stats three, and scoreboard or any given data: " ) date = input( "Enter the date of the data that you want in the format of YYYYMMDD: ") if data_category == "all": for x in range(0, len(data_type)): if season_name_type == "playoff": Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data(league=league_name, season=season_name_begin + season_name_type, feed=data_type[x], format=file_format, fordate=date) #can add more optional params manually else: Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data(league=league_name, season=season_name_begin + season_name_end + season_name_type, feed=data_type[x], format=file_format, fordate=date) #can add more optional params manually else: if season_name_type == "playoff": Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data(league=league_name, season=season_name_begin + season_name_type, feed=data_category, format=file_format, fordate=date) #can add more optional params manually else: Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data( league=league_name, season=season_name_begin + season_name_end + season_name_type, feed=data_category, format=file_format, fordate=date)
def request_game(): initial_inputs() data_type = ["game_playbyplay", "game_boxscore", "game_startinglineup"] data_category = input( "Enter 'all' for game_playbyplay,game_boxscore,and game_startinglineup or any given data: " ) gameid = input( "Enter game id in the form of:game date YYYYMMDD + '-'+ away team abbr +'-'+ home team abbr. Example 20161212-BOS-CLE: " ) if data_category == "all": for x in range(0, len(data_type)): if season_name_type == "playoff": Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data(league=league_name, season=season_name_begin + season_name_type, feed=data_type[x], format=file_format, gameid=gameid) #can add more optional params manually else: Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data(league=league_name, season=season_name_begin + season_name_end + season_name_type, feed=data_type[x], format=file_format, gameid=gameid) #can add more optional params manually else: if season_name_type == "playoff": Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data(league=league_name, season=season_name_begin + season_name_type, feed=data_category, format=file_format, gameid=gameid) #can add more optional params manually else: Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data( league=league_name, season=season_name_begin + season_name_end + season_name_type, feed=data_category, format=file_format, gameid=gameid)
def request_gamelogs(): initial_inputs() data_category = input( "enter either 'player' or 'team' to request for data: ") if data_category == "player": player = input( "Enter the player's name in the form of: last name, first-last,first-last-playerID: " ) if season_name_type == "playoff": Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data(league=league_name, season=season_name_begin + season_name_type, feed="player_gamelogs", format=file_format, player=player) #can add more optional params manually else: Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data( league=league_name, season=season_name_begin + season_name_end + season_name_type, feed="player_gamelogs", format=file_format, player=player) #can add more optional params manually else: team = input( "Enter the team's abbr in the form of: abbreviation or city-teamname" ) if season_name_type == "playoff": Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data(league=league_name, season=season_name_begin + season_name_type, feed="team_gamelogs", format=file_format, team=team) #can add more optional params manually else: Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data( league=league_name, season=season_name_begin + season_name_end + season_name_type, feed="team_gamelogs", format=file_format, team=team)
def __init__(self): self.seasons = ['2019-regular', '2017-regular', '2017-playoff', '2018-regular', '2018-playoff'] #self.seasons = ['2019-regular'] apikey = '98de7b49-a696-4ed7-8efa-94b28a' self.msf = MySportsFeeds(version="2.0") self.msf.authenticate(apikey, "MYSPORTSFEEDS") self.bqu = BigqueryUtils()
def __init__(self, version, api_key, password, call_file): self.__conn = MySportsFeeds(version=version) self.__conn.authenticate(api_key, password) self.__call_signature = {} self.call_signatures = {} with open(call_file) as f: self.call_signatures = json.load(f)
def request_general(): file_format = "json" league_name = input("League name: ") season_name_begin = input("Enter the beginning of the season ") + "-" season_name_end = input("Enter the end of the season ") + "-" season_name_type = input("Enter either 'regular' or 'playoff '") data_type = [ "cumulative_player_stats", "full_game_schedule", "active_players", "overall_team_standings", "conference_team_standings", "division_team_standings", "playoff_team_standings", "player_injuries", "latest_updates" ] #for loop to download all the data at a given season for x in range(0, len(data_type)): if season_name_type == "playoff": Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data(league=league_name, season=season_name_begin + season_name_type, feed=data_type[x], format=file_format) #can add more optional params manually elif data_type[x] == "playoff_team_standings": Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data(league=league_name, season=season_name_begin + "playoff", feed=data_type[x], format=file_format) #can add more optional params manually else: Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data( league=league_name, season=season_name_begin + season_name_end + season_name_type, feed=data_type[x], format=file_format)
def import_game(import_date): """imports game for the selected date (YYYYMMDD)""" msf = MySportsFeeds(version='1.0') msf.authenticate(username, password) try: output = msf.msf_get_data(league='nhl', season='current', feed='scoreboard', fordate=import_date, team=fav_team, format='json') return True except Warning: print("Import failed") return False
def __init__(self, stats=None): self.temp_file = tempfile.TemporaryFile() self.logger = logging.getLogger() self.logger.setLevel(logging.INFO) self.user_name = os.environ['sport_user'] self.password = os.environ['sport_password'] self.feed = MySportsFeeds(version="1.1", store_type=None) self.feed.authenticate(self.user_name, self.password) self.stats = stats self.stat_data = None self.score_data = None
def msf(season, feed, team): # f = open(('E:/school/2018-19/caps/A Foot in the Door/json/%(feed)s-nfl-%(season)s.json' % # {'feed': feed, 'season': season}), 'w+') msf = MySportsFeeds(version ='1.2') msf.authenticate('API_KEY', 'PASSWORD') output = msf.msf_get_data(force = 'true', league='nfl', feed = feed, season=season, format='json', team = team) #, position = 'te' # f.write(output) # json.dump(output, f) return output
def __init__(self, api_key=None): if api_key is None: print("Api key is null, getting it from env var LS_API_KEY") self.api_key = os.environ.get('LS_API_KEY') if self.api_key is None: raise ValueError( "Api key not passed in and not available under env var LS_API_KEY" ) self.mysportsfeeds_client = MySportsFeeds('2.0', verbose=True) self.mysportsfeeds_client.authenticate(api_key, 'MYSPORTSFEEDS') self.scoreboards = [] self.games_today = []
def setup_import(): msf = MySportsFeeds(version='1.0') msf.authenticate(username, password) try: output = msf.msf_get_data(league='nhl', season='current', feed='full_game_schedule', team=fav_team, format='json') output = msf.msf_get_data(league='nhl', season='current', feed='team_gamelogs', team=fav_team, format='json') print("Import succesful") return True except Warning or FileNotFoundError: print("Import failed") return False
def request_all_player_gamelogs(player_list): initial_inputs() data_category = 'player' for key in player_list: if season_name_type == 'playoff': Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data(league=league_name, season=season_name_begin + season_name_type, feed="player_gamelogs", format=file_format, player=key) else: Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate(authorize.username, authorize.password) Output = Data_query.msf_get_data( league=league_name, season=season_name_begin + season_name_end + season_name_type, feed="player_gamelogs", format=file_format, player=key)
def getDailyPlayerStatsData(df): Data_query = MySportsFeeds('1.0', verbose=True) Data_query.authenticate('poly91', 'abel1234') for gameDate in df['Game Date'].tolist(): print(gameDate) try: Output = Data_query.msf_get_data(league='nba', season='2016-2017-regular', feed='daily_player_stats', fordate=str(gameDate), format='csv', sort='player.team') except: print("errorinfo: ", sys.exc_info()[0]) print('Issue with %d', gameDate)
def main(): # Create instance of MySportsFeeds API and authenticate msf = MySportsFeeds('2.1', verbose=False) msf.authenticate(config.MySportsFeeds_key, config.msfPassword) # Create MongoDB client instance client = pymongo.MongoClient( 'mongodb+srv://' + config.mongoBlock + ':' + config.mongoBlockPW + '@nba-data.nftax.azure.mongodb.net/NBA-ML?retryWrites=true&w=majority') season = '2020-2021-regular' # updateYesterdayData(msf, client, season) # predictTodayGames(msf, client, season) updateTodaySpreads(msf, client, season)
def pull_game_logs(player_names, stats_of_interest): msf_user = "" msf_pass = "" with open("inputs/msf.txt", "r") as my_file: msf_user = my_file.readline() #Pull game logs for various player names and returns dfs. msf = MySportsFeeds(version="1.2") msf.authenticate("e09cc51e-beb1-43ac-b888-20a591", "0010RugbyFight") output = msf.msf_get_data(league='nba', season='2018-2019-regular', feed='player_gamelogs', format='json', player=player_names, sort="player.lastname") gamelogs = output['playergamelogs']['gamelogs'] return gamelogs
def get_output_from_api(username, password): # where api json file is stored path = 'results/roster_players-nfl-2017-2018-regular.json' # load json from results cache if Path(path).exists(): with open(path, 'r') as f: output = json.load(f) # make request to API if no cache else: msf = MySportsFeeds(version="1.2", verbose=True) msf.authenticate(username, password) output = msf.msf_get_data(league='nfl', season='2017-2018-regular', feed='roster_players', format='json') return output
def main(): # Create instance of MySportsFeeds API and authenticate msf = MySportsFeeds('2.1', verbose=False) msf.authenticate(config.MySportsFeeds_key, config.msfPassword) teamDict = {} output = msf.msf_get_data(feed='seasonal_team_stats', league='nba', season='2019-2020-regular', format='json', force='true') for team in output['teamStatsTotals']: teamInfo = team['team'] teamDict[teamInfo[ 'abbreviation']] = teamInfo['city'] + ' ' + teamInfo['name'] unitsFilename = '../features/dictionaries/teamAbbrevToName.json' with open(unitsFilename, 'w') as outFile: json.dump(teamDict, outFile, indent=4, separators=(',', ': ')) return 0
def get_player_info(player_name): player_name = player_name.lower() player_name = player_name.replace(' ', '-') msf = MySportsFeeds(version="1.2") msf.authenticate("cameronchandra", "29Malysana") output = msf.msf_get_data(league='mlb', season='latest', format='json', feed='cumulative_player_stats', player=player_name) mlb_team = output['cumulativeplayerstats']['playerstatsentry'][0]['team'][ 'Abbreviation'] position = output['cumulativeplayerstats']['playerstatsentry'][0][ 'player']['Position'] avg = output['cumulativeplayerstats']['playerstatsentry'][0]['stats'][ 'BattingAvg']['#text'] hr = output['cumulativeplayerstats']['playerstatsentry'][0]['stats'][ 'Homeruns']['#text'] steals = output['cumulativeplayerstats']['playerstatsentry'][0]['stats'][ 'StolenBases']['#text'] runs = output['cumulativeplayerstats']['playerstatsentry'][0]['stats'][ 'Runs']['#text'] return mlb_team, position, avg, hr, steals, runs
def main(): client = pymongo.MongoClient( 'mongodb+srv://' + config.mongoBlock + ':' + config.mongoBlockPW + '@nba-data.nftax.azure.mongodb.net/NBA-ML?retryWrites=true&w=majority') # Create instance of MySportsFeeds API and authenticate msf = MySportsFeeds('2.1', verbose=False) msf.authenticate(config.MySportsFeeds_key, "MYSPORTSFEEDS") season = '2020-2021-regular' # df = pd.read_csv('../features/gameData/' + season + 'games.csv').set_index('gameID', drop=False) # updateTodayGames(msf, client, season) deleteUnplayedGames(client, season) insertUnplayedGames(msf, client, season) # insertGamesFromCSV(client, season) # df = pd.read_csv('../features/gameData/' + season + '-games.csv').set_index('gameID', drop=False) # updateGames(msf, client, season, df) client.close()
def main(): # Create instance of MySportsFeeds API and authenticate msf = MySportsFeeds('2.1', verbose=False) msf.authenticate(config.MySportsFeeds_key, "MYSPORTSFEEDS") # seasons = [] season = '2020-2021-regular' # addDateStintsToCSV(season, '20200728', 100) # outputStintCSV(msf, season) dateStart = '' dateEnd = '' printRatings = True # for season in seasons: ratingBasePath = getBasePath(season, dateStart, dateEnd, 'RAPM-ratings') inputBasePath = getBasePath(season, dateStart, dateEnd, 'RAPM-inputs') # if config.debug: print("Analyzing play-by-play data for " + season + "... ") units, points, weights = extractPbpData(msf, season, dateStart, dateEnd) # unitsImported, pointsImported, weightsImported = importPbpDataFromJSON(inputBasePath) # if config.debug: print("Getting player names...") playerDict = getPlayerNames(msf, season) # if config.debug: print("exporting play-by-play to JSON... ") exportPbpDataToJSON(units, points, weights, inputBasePath) # if config.debug: print("Calculating RAPM...") ratings = calculateRAPM(units, points, weights) # ratingsImported = calculateRAPM(unitsImported[:224], pointsImported[:224], weightsImported[:224]) if printRatings: for rating in ratings: print(rating[0], "{}".format(playerDict[int(rating[0])]), "{0:.3f}".format(rating[1])) # if config.debug: print("Export RAPM ratings...") exportPlayerRatings(ratings, playerDict, ratingBasePath)
from ohmysportsfeedspy import MySportsFeeds from cryptography.fernet import Fernet import json with open('key.txt', 'r') as myfile: key = myfile.read() f = Fernet(key) token = 'gAAAAABboxejr3hkCDwGeNSEQDPjLbw2T-M41JclD-7ZqqhZWAM61cjqybisLMBFdARpk4L0NsX90tpRNabJcr-oP31W--eiqcbbE8Qe5ZOz9273CdNy5Ts=' msf = MySportsFeeds(version="2.0", store_type='file', store_location='results/') msf.authenticate(f.decrypt(token), "MYSPORTSFEEDS") output = msf.msf_get_data(league='nfl', season='2016-playoff', feed='seasonal_games', format='json') print output
def __init__(self, v='1.2'): self.msf = MySportsFeeds(version=v) self.msf.authenticate(environ['apikey_token'], environ['password'])
from ohmysportsfeedspy import MySportsFeeds Data_query = MySportsFeeds('2.0', verbose=True) Data_query.authenticate('7a623d32-510c-4ccf-8a7b-8a3af9', 'MYSPORTSFEEDS') Output = Data_query.msf_get_data(league='nba', season='2018-2019-regular', feed='seasonal_player_gamelogs', player='anthony-davis', format='json', force='true') print(Output)
import json import datetime import numpy as np import pandas as pd from ohmysportsfeedspy import MySportsFeeds from pandas.io.json import json_normalize #package for flattening json in pandas df msf = MySportsFeeds(version='2.0') msf.authenticate("API KEY", "MYSPORTSFEEDS") # Pull JSON from My Sports Feeds API year = 2019 days = [ datetime.datetime(year, 4, 3) + datetime.timedelta(days=i) for i in range(188) ] days = [day for day in days] game_date = [day.strftime("%Y%m%d") for day in days] count = len(days) for date in game_date: json_gamelog = msf.msf_get_data(league='mlb', season='2019-regular', feed='players', format='json', date=str(date)) print(count) count = count - 1 # Read and format JSON
# Install MySportsFeed and simplejson # pip install ohmysportsfeedspy # pip install simplejson from ohmysportsfeedspy import MySportsFeeds import pymongo import requests import json # Authenticating the MySportsFeeds API Data_query = MySportsFeeds('1.2',verbose=True) Data_query.authenticate('Aiyana410', '04101993mad') # The default port used by MongoDB is 27017 # https://docs.mongodb.com/manual/reference/default-mongodb-port/ conn = 'mongodb://localhost:27017' client = pymongo.MongoClient(conn) # Declare the database db = client.nba # Declare the collection collection = db.nba_bio # Google API Servcies key gkey ="Use your Google API Service Key" # List of seasons needed season=['2015-2016','2016-2017'] # Intializing the index for each document being stored index=1
def __init__(self): self.feed = MySportsFeeds(version='1.0') self.feed.authenticate('rresma2', 'sportsapp') self.season = '2016-2017-regular' self.league = 'nba' self.format = 'json'
import wikipedia import googlemaps import re import forecastio from ohmysportsfeedspy import MySportsFeeds gmaps_key = "AIzaSyArLBOGZk0mH_VKEMUjnyvLLLNRR2w9BcA" forecast_key = "9acf53a7de55294989b3f3904e8a8d57" msf = MySportsFeeds(version="1.2", store_type=None, store_location=None) msf.authenticate("kvanderheiden", "lucidata506") MAX_CHAR = 500 cli = googlemaps.Client(key=gmaps_key) def api_handler(app, data): ''' This acts as an interface between the sms handler and call to an external API. Data is retreived from a specific API and sent back to the sms handler ''' # determine API to call based on app param if app.name == "wikipedia": return wiki_handler(data) if app.name == "directions": return dir_handler(data) if app.name == "weather": return weather_handler(data) if app.name == "sports": return sports_handler(data)
import pdb import os import time from ohmysportsfeedspy import MySportsFeeds import json import sys msf = MySportsFeeds(version="1.0") msf.authenticate("kendallweihe", os.environ["PWD_MSF"]) def get_dates(): game_dates = [] year = "2015" for i in range(10, 13): for j in range(1, 32): date = "{}{}{}".format(year, i, str(j).zfill(2)) game_dates.append(date) year = "2016" for i in range(1, 8): for j in range(1, 32): date = "{}{}{}".format(year, str(i).zfill(2), str(j).zfill(2)) game_dates.append(date) return game_dates def get_daily_player(date): time.sleep(5) stats = msf.msf_get_data(league="nba",
from ohmysportsfeedspy import MySportsFeeds import datetime msf = MySportsFeeds(version='2.1',verbose=True) msf.authenticate("API KEY", "MYSPORTSFEEDS") # Pull CSV from My Sports Feeds API year = 2016 days = [datetime.datetime(year, 4, 3) + datetime.timedelta(days=i) for i in range(183)] game_date = [day.strftime("%Y%m%d") for day in days] for day in game_date: output = msf.msf_get_data(league='mlb',season=str(year)+'-regular',feed='daily_player_gamelogs' ,format='json', date=day, fordate=day)