Пример #1
0
def hist_web_lineups():
    table = 'hist_lineup_optimizers'
    recordset = dbo.get_table_last_row(table, 'Date')
    todays_date = time.strftime("%Y-%m-%d")
    if str(recordset[0][0]) == todays_date:
        print "hist_web_lineups: a recordset already exists in table: %s for entered date" % table
        time.sleep(5)
        return
    if TeamOdds.get_team_odds('MLB')[1].split()[1] != todays_date.split(
            '-')[2]:  #Refactor
        print "MLB team odds are not for today"
        time.sleep(5)
        mlb_odds = ''
    else:
        mlb_odds = json.dumps(TeamOdds.get_team_odds('MLB')[0])
    # if TeamOdds.get_team_odds('NHL')[1].split()[1]!=todays_date.split('-')[2]:
    #     print "NHL team odds are not for today"
    #     time.sleep(5)
    #     nhl_odds=''
    # else:
    #     nhl_odds=json.dumps(TeamOdds.get_team_odds('NHL')[0])
    nhl_odds = ''
    nba_odds = ''
    # if TeamOdds.get_team_odds('NBA')[1].split()[1]!=todays_date.split('-')[2]:
    #     print "NBA team odds are not for today"
    #     time.sleep(5)
    #     nba_odds=''
    # else:
    #     nba_odds=json.dumps(TeamOdds.get_team_odds('NBA')[0])
    dfn_nba = Cell('Backtest_Parameters', 'clDFNNBA').value
    dfn_mlb = Cell('Backtest_Parameters', 'clDFNMLB').value
    rw_nba = Cell('Backtest_Parameters', 'clRWNBA').value
    rw_mlb = Cell('Backtest_Parameters', 'clRWMLB').value
    rw_nhl = Cell('Backtest_Parameters', 'clRWNHL').value
    rn_nba = Cell('Backtest_Parameters', 'clRNNBA').value
    rn_nhl = Cell('Backtest_Parameters', 'clRNNHL').value
    rn_mlb = Cell('Backtest_Parameters', 'clRNMLB').value
    db_data = [
        todays_date, dfn_nba, dfn_mlb, rw_nba, rw_mlb, rw_nhl, mlb_odds,
        rn_nba, rn_nhl, rn_mlb, nba_odds, nhl_odds
    ]
    columns = 'Date,DFN_NBA,DFN_MLB,RW_NBA,RW_MLB,RW_NHL,MLB_ODDS,RN_NBA,RN_NHL,RN_MLB,NBA_ODDS,NHL_ODDS'
    placeholders = ', '.join(['%s'] * len(db_data))
    print 'now historizing'
    dbo.insert_mysql(table, columns, db_data, placeholders)
    print 'web_lineups historized succesfully'
    return
Пример #2
0
	def enter_contest(self,contest_url,roster_data,entered_contest):#Cole: Need to wrtie to db on succesful entry
		print contest_url
		r = self.session.post(contest_url,json.dumps(roster_data),headers=self.headers)
		if r.status_code == 201:
			print "entry success"
			os.system('pause')
			cols =  ", ".join([key for key in entered_contest.keys()])
			values =  ", ".join(['"' + json.dumps(data).replace('"',"'") + '"' for data in entered_contest.values()])
			dbo.insert_mysql("fanduel_contests", cols, values)
			return True
		else:
			print 'entry failed with HTTP error ' + str(r.status_code)
			print r.text
			entry_id = 0
			entry_status = 'failed'
			os.system('pause')
			return False
Пример #3
0
def hist_FD_playerdata(Sport,Url,ContestID):
    #player_map = Ugen.excel_mapping('Player Map',1,2)
    FD_dict = ast.literal_eval(Uds.parse_html(Url,"FD.playerpicker.allPlayersFullData = ",";"))
    todays_date=time.strftime("%Y-%m-%d")
    db_data=[]
    # print Url
    for fd_key in FD_dict:
        player_name=FD_dict[fd_key][1]
        position=FD_dict[fd_key][0]
        FD_Salary=FD_dict[fd_key][5]
        FD_FPPG=FD_dict[fd_key][6]
        FD_GP=FD_dict[fd_key][7]
        db_data=[ContestID,Sport,todays_date,player_name,FD_Salary,FD_FPPG,FD_GP,position]
        columns='contestID,Sport,Date,Player,FD_Salary,FD_FPPG,FD_GP,Position'
        placeholders = ', '.join(['%s'] * len(db_data))
        table='hist_fanduel_data'
        #print 'now historizing %s contest#: %d player %s' % (Sport,ContestID,player_name)
        dbo.insert_mysql(table,columns,db_data,placeholders)
    return
Пример #4
0
def hist_web_lineups():
    table='hist_lineup_optimizers'
    recordset=dbo.get_table_last_row(table,'Date')
    todays_date=time.strftime("%Y-%m-%d")
    if str(recordset[0][0])==todays_date:
        print "hist_web_lineups: a recordset already exists in table: %s for entered date" % table
        time.sleep(5)   
        return
    if TeamOdds.get_team_odds('MLB')[1].split()[1]!=todays_date.split('-')[2]: #Refactor 
        print "MLB team odds are not for today"
        time.sleep(5)
        mlb_odds=''
    else:
        mlb_odds=json.dumps(TeamOdds.get_team_odds('MLB')[0])
    # if TeamOdds.get_team_odds('NHL')[1].split()[1]!=todays_date.split('-')[2]:
    #     print "NHL team odds are not for today"
    #     time.sleep(5)
    #     nhl_odds=''
    # else:
    #     nhl_odds=json.dumps(TeamOdds.get_team_odds('NHL')[0])
    nhl_odds=''
    nba_odds=''    
    # if TeamOdds.get_team_odds('NBA')[1].split()[1]!=todays_date.split('-')[2]:
    #     print "NBA team odds are not for today"
    #     time.sleep(5)
    #     nba_odds=''
    # else:
    #     nba_odds=json.dumps(TeamOdds.get_team_odds('NBA')[0])
    dfn_nba=Cell('Backtest_Parameters','clDFNNBA').value
    dfn_mlb=Cell('Backtest_Parameters','clDFNMLB').value
    rw_nba=Cell('Backtest_Parameters','clRWNBA').value
    rw_mlb=Cell('Backtest_Parameters','clRWMLB').value
    rw_nhl=Cell('Backtest_Parameters','clRWNHL').value
    rn_nba=Cell('Backtest_Parameters','clRNNBA').value
    rn_nhl=Cell('Backtest_Parameters','clRNNHL').value
    rn_mlb=Cell('Backtest_Parameters','clRNMLB').value  
    db_data=[todays_date,dfn_nba,dfn_mlb,rw_nba,rw_mlb,rw_nhl,mlb_odds,rn_nba,rn_nhl,rn_mlb,nba_odds,nhl_odds]
    columns='Date,DFN_NBA,DFN_MLB,RW_NBA,RW_MLB,RW_NHL,MLB_ODDS,RN_NBA,RN_NHL,RN_MLB,NBA_ODDS,NHL_ODDS'
    placeholders = ', '.join(['%s'] * len(db_data))
    print 'now historizing'
    dbo.insert_mysql(table,columns,db_data,placeholders)
    print 'web_lineups historized succesfully'
    return
Пример #5
0
	def parse_event_data(self,event_data,event_date,odds_data): #Ian: needs to be updated for mongodb
		event_data_dict = {}
		if event_data:
			event_data_dict['event_id'] = event_data['event_id']
			event_data_dict['sport'] = event_data['sport']
			event_data_dict['start_date_time'] = event_data['start_date_time']
			event_data_dict['season_type'] = event_data['season_type']
			event_data_dict['away_team'] = event_data['away_team']['team_id']
			event_data_dict['home_team'] = event_data['home_team']['team_id']
			home_team = event_data['home_team']['abbreviation']
			away_team = event_data['away_team']['abbreviation']
			event_data_dict['vegas_odds']={}
			try:
				event_data_dict['vegas_odds'][home_team]=odds_data[home_team]
				event_data_dict['vegas_odds'][away_team]=odds_data[away_team]
			except KeyError:
				print ('no vegas odds for event: %s' % event_data['event_id'])
			event_data_dict['stadium'] = event_data['home_team']['site_name']
			event_date = event_date[0:4] + "-" + event_date[4:6] + "-" + event_date[6:8]
			team_dict,player_dict = ds.mlb_starting_lineups(event_date)
			if home_team in team_dict and away_team in team_dict:
				if 'PPD' not in team_dict[home_team]['start_time']:
					wunderground_dict=weather.weather_hist(home_team,event_date,team_dict[home_team]['start_time'])
				try:			
					event_data_dict['wunderground_forecast']=wunderground_dict
					event_data_dict['wind']=str(wunderground_dict['wind']['wind_dir'])+'_'+str(wunderground_dict['wind']['wind_speed'])
				except:
					print ('no weather data for %s' % event_data_dict['event_id'])
				event_data_dict['home_starting_lineup'] = team_dict[home_team]['lineup']
				event_data_dict['away_starting_lineup'] = team_dict[away_team]['lineup']
				event_data_dict['forecast'] = team_dict[home_team]['weather_forecast']
				if team_dict[home_team]['start_time'] == 'PPD':
					event_data_dict['PPD'] = True
				else:
					event_data_dict['PPD'] = False
			else:
				print ('no data from baseball lineups website for this event')
			cols = ", ".join(event_data_dict.keys())
			data = ", ".join(['"' + unicode(v) + '"' for v in event_data_dict.values()])
			dbo.insert_mysql('event_data',cols,data)
		return event_data_dict
Пример #6
0
def hist_FD_playerdata(Sport, Url, ContestID):
    #player_map = Ugen.excel_mapping('Player Map',1,2)
    FD_dict = ast.literal_eval(
        Uds.parse_html(Url, "FD.playerpicker.allPlayersFullData = ", ";"))
    todays_date = time.strftime("%Y-%m-%d")
    db_data = []
    # print Url
    for fd_key in FD_dict:
        player_name = FD_dict[fd_key][1]
        position = FD_dict[fd_key][0]
        FD_Salary = FD_dict[fd_key][5]
        FD_FPPG = FD_dict[fd_key][6]
        FD_GP = FD_dict[fd_key][7]
        db_data = [
            ContestID, Sport, todays_date, player_name, FD_Salary, FD_FPPG,
            FD_GP, position
        ]
        columns = 'contestID,Sport,Date,Player,FD_Salary,FD_FPPG,FD_GP,Position'
        placeholders = ', '.join(['%s'] * len(db_data))
        table = 'hist_fanduel_data'
        #print 'now historizing %s contest#: %d player %s' % (Sport,ContestID,player_name)
        dbo.insert_mysql(table, columns, db_data, placeholders)
    return
Пример #7
0
 def enter_contest(
         self, contest_url, roster_data,
         entered_contest):  #Cole: Need to wrtie to db on succesful entry
     print contest_url
     r = self.session.post(contest_url,
                           json.dumps(roster_data),
                           headers=self.headers)
     if r.status_code == 201:
         print "entry success"
         os.system('pause')
         cols = ", ".join([key for key in entered_contest.keys()])
         values = ", ".join([
             '"' + json.dumps(data).replace('"', "'") + '"'
             for data in entered_contest.values()
         ])
         dbo.insert_mysql("fanduel_contests", cols, values)
         return True
     else:
         print 'entry failed with HTTP error ' + str(r.status_code)
         print r.text
         entry_id = 0
         entry_status = 'failed'
         os.system('pause')
         return False
Пример #8
0
def enter_best_contests(s,session_id,bet_sport,max_bet,potential_contests,time_remaining,wins_data,bin_size):
	current_bet = 0
	with open('C:/Users/Cole/Desktop/Fanduel/fanduel/userwinscache.txt',"r") as myfile:
		data = myfile.read()
	user_wins_cache = ast.literal_eval(data)
	with open('C:/Users/Cole/Desktop/Fanduel/fanduel/roster.txt',"r") as myfile:
		data = myfile.read()
	strategy_data = ast.literal_eval(data)
	for contest in potential_contests:
		if current_bet < max_bet:
			entry_url = 'https://www.fanduel.com/pg/Lobby/showTableEntriesJSON/' + contest['contest_id'] + '/0/10000'
			response = urllib2.urlopen(entry_url)
			shtml = response.read()
			entry_dict = ast.literal_eval(shtml)
			user_wins_array = {'Total':[],'NFL':[],'MLB':[],'NBA':[],'NHL':[],'CBB':[],'CFB':[]}
			for entry_data in entry_dict['entries']:
				user_html = entry_data['userHTML']
				intStart = user_html.find("alt=''>")
				intEnd = user_html.find('<',intStart)
				username = user_html[intStart:intEnd].replace("alt=''>","")
				if username in user_wins_cache.keys():
					for sport,wins in user_wins_cache[username].iteritems():
						user_wins_array[sport].append(wins)
				else:
					user_url = 'https://www.fanduel.com/users/'+username
					response = urllib2.urlopen(user_url)
					shtml = response.read()
					soup = BeautifulSoup(shtml)
					table = soup.find('table', {'class': 'condensed'})
					td = table.find('th').findNext('td')
					user_wins_cache[username] = {}
					for th in table.findAll('th'):
						try:
							user_wins_array[th.text].append(int(td.text))
							user_wins_cache[username][th.text] = int(td.text)
							td = td.findNext('td')
						except ValueError:
							user_wins_array[th.text].append(0)
							user_wins_cache[username][th.text] = 0
							td = td.findNext('td')					
						except KeyError:
							pass	
					time.sleep(1)
			arr = numpy.array(user_wins_array[bet_sport])
			print arr
			avg_top_wins = numpy.mean(arr)#Need to decide best stats for paticualar contest type
			print avg_top_wins
			contest_utility,future_utility = get_contest_utlity(avg_top_wins,time_remaining,wins_data,bin_size)
			print (contest_utility, future_utility)
			if contest_utility > future_utility and current_bet < max_bet and contest['entryFee']<=(max_bet - current_bet):
				print 'entry attempt'
				player_data = str(strategy_data['player_data'])
				entry_id,entry_status = fdo.enter_contest(s,session_id,'https://www.fanduel.com/e/Game/' + contest['game_id'] + '?tableId=' + contest['contest_id'] + '&fromLobby=true',player_data)
				print entry_status
				contest['avg_top_wins'] = avg_top_wins
				contest['entry_id'] = entry_id
				contest['strat_params'] = str(strategy_data['strat_params'])
				if entry_status == 'success':
					current_bet = current_bet + contest['entryFee']
					placeholders = ', '.join(['%s'] * len(contest))
					columns = ', '.join(contest.keys())
					dbo.insert_mysql('FD_table_contests',columns,placeholders,contest.values())
	with open('C:/Users/Cole/Desktop/Fanduel/fanduel/userwinscache.txt',"w") as myfile:
		myfile.write(str(user_wins_cache))
	return current_bet