def hist_FD_contest_salaries(): todays_date = dt.datetime.strptime(time.strftime("%Y-%m-%d"), "%Y-%m-%d") pp = pprint.PrettyPrinter(indent=4) FDSession = fdo.FDSession() sport_list = ['NBA', 'NHL', 'NFL', 'MLB'] for sport in sport_list: daily_contests = FDSession.get_daily_contests(sport) for contest_ID, contest_url in daily_contests.iteritems(): player_dict = { player['first_name'] + ' ' + player['last_name']: { 'fppg': player['fppg'], 'salary': player['salary'], 'position': player['position'], 'games_played': player['played'], 'injury_status': player['injury_status'] } for player in FDSession.fanduel_api_data(contest_url) ['players'] } print 'now historizing %s contest: %s' % (sport, contest_ID) dbo.write_to_db( 'hist_fanduel_data', { 'sport': sport, 'date': todays_date, 'contest_ID': contest_ID, 'contest_dict': player_dict }, False) print 'contest: %s historized successfully' % sport return
def parse_boxscore_data(self,boxscore_data): player_map = {}#Ugen.excel_mapping("Player Map",6,5) #Ian: this needs to be generalized for each sport if boxscore_data: for dataset,data_model in self.data_model.iteritems(): for player in boxscore_data[dataset]: player_data={} player_data['gameID'] = self.gameid player_data['sport'] = self.sport player_data['player_type'] = self.player_type_map[dataset] player_data['date'] = dt.datetime.strptime(self.gameid[0:8],'%Y%m%d') meta_cols = [col for col in player_data.keys()] for datum,val in data_model.iteritems(): if datum[0] == '$': #Cole: prefix with $ denotes hard coded value player_data[val] = datum[1:] elif player[datum] == True: #Cole: Convert bool to int for db write player_data[val] = 1 elif player[datum] ==False: player_data[val] = 0 elif datum == 'display_name': #Cole: this deals with the player mapping on the front end, so whats in db matches FD if player[datum] in player_map.keys(): player_data[val] = player_map[player[datum]] else: player_data[val] = player[datum] else: player_data[val] = player[datum] dbo.write_to_db('hist_player_data',player_data,False) return self
def get_live_contest_ids(): s, session_id = fdo.get_fanduel_session() r = s.get( 'https://www.fanduel.com/mycontests/162491/live?start=0&number=10000') live_contest_dict = json.loads(r.text) for contest in live_contest_dict['seats']: dbo.write_to_db('FD_table_contests', 'table_id,contest_id', [str(contest[2].split(r'/')[2]), str(contest[0])])
def write_nhl_game_data(team_data,player_team,sGameID): player_num_lookup = get_NHL_team_players(player_team) for player_types in team_data.values(): for player_stats in player_types: ordered_player_stats = collections.OrderedDict(sorted(player_stats.items())) try: player = player_num_lookup[player_stats['num']] except KeyError: print str(player_stats['num']) + " KeyError" player = str(player_stats['num']) + " KeyError" dbo.write_to_db('hist_player_data','Sport,Player, GameID, Team',['NHL',player,sGameID,player_team],ordered_player_stats) return 'data succesfully loaded'
def hist_FD_contest_salaries(): todays_date=dt.datetime.strptime(time.strftime("%Y-%m-%d"),"%Y-%m-%d") pp = pprint.PrettyPrinter(indent=4) FDSession = fdo.FDSession() sport_list=['NBA','NHL','NFL','MLB'] for sport in sport_list: daily_contests = FDSession.get_daily_contests(sport) for contest_ID,contest_url in daily_contests.iteritems(): player_dict={player['first_name']+' '+player['last_name']:{'fppg':player['fppg'],'salary':player['salary'],'position':player['position'], 'games_played':player['played'],'injury_status':player['injury_status']} for player in FDSession.fanduel_api_data(contest_url)['players']} print 'now historizing %s contest: %s' % (sport,contest_ID) dbo.write_to_db('hist_fanduel_data',{'sport':sport,'date':todays_date,'contest_ID':contest_ID,'contest_dict':player_dict},False) print 'contest: %s historized successfully' % sport return
def parse_event_data(self,boxscore_data): event_data={} if boxscore_data: event_data['gameID']=self.gameid event_data['sport']=self.sport event_data['date']=dt.datetime.strptime(self.gameid[0:8],'%Y%m%d') event_data['away_period_scores']=boxscore_data['away_period_scores'] event_data['away_team']=boxscore_data['away_team']['abbreviation'] event_data['home_period_scores']=boxscore_data['home_period_scores'] event_data['home_team']=boxscore_data['home_team']['abbreviation'] event_data['away_totals']={val:boxscore_data['away_totals'][key] for key,val in self.totals_data_model.iteritems()} event_data['home_totals']={val:boxscore_data['home_totals'][key] for key,val in self.totals_data_model.iteritems()} event_data['event_information']={key:boxscore_data['event_information'][key] for key in self.event_info_data_model} event_data['officials']=[official['first_name']+' '+official['last_name'] for official in boxscore_data['officials']] dbo.write_to_db('hist_event_data',event_data,False) return
def get_live_contest_ids(): s, session_id = fdo.get_fanduel_session() r = s.get('https://www.fanduel.com/mycontests/162491/live?start=0&number=10000') live_contest_dict = json.loads(r.text) for contest in live_contest_dict['seats']: dbo.write_to_db('FD_table_contests','table_id,contest_id',[str(contest[2].split(r'/')[2]),str(contest[0])])