예제 #1
0
def hist_FD_contest_salaries():
    todays_date=time.strftime("%Y-%m-%d")
    table='hist_fanduel_data'
    recordset=dbo.get_table_last_row(table,'Date')
    if str(recordset[0][1])==todays_date:
        print "hist_fd_contest_salares: salaries already historized in %s for today " % table
        time.sleep(5)   
        return
    s,session_id=fdo.get_fanduel_session()
    contest_dict=fdo.get_FD_contests(s)
    sports_list=['mlb','nba','nhl','nfl'] #pick this option if you wanna historize all sports
    #sports_list=['mlb','nba']
    for sport in sports_list:
        print sport
        sport_contest_dict=(x for x in contest_dict if x['sport']==sport)
        test_dict_case=(x for x in contest_dict if x['sport']==sport) #assign duplicate var to avoid list mutation
        if len(list(test_dict_case))>0: #test if there are contests for the sport
            historized_contests=[]
            ContestID=''
            rw=1
            for contest in sport_contest_dict: #loop through each for given sport
                Url='https://www.fanduel.com/e/Game'+contest['entryURL'][contest['entryURL'].find('Game\\')+5:]
                # print contest['startString']
                if  contest['gameId'] not in historized_contests and len(contest['startString'])<14 and contest['entryURL'].find('accept_public_challenge')==-1: #check for contests at other times
                    print 'now historizing %s contest#: %d' % (sport,contest['gameId'])
                    hist_FD_playerdata(sport.upper(),Url,contest['gameId'])
                    print '%s contest#: %d historized succesfully' % (sport,contest['gameId'])
                    historized_contests.append(contest['gameId'])
    fdo.end_fanduel_session(s)
    return
예제 #2
0
파일: main.py 프로젝트: emschorsch/fanduel
def run_enter_best_contests(daily_bet,bin_size):
	s, session_id = fdo.get_fanduel_session()
	total_bet = 0
	time_remaining = Ugen.get_time_remain('17:00')
	wins_data = build_pWins_vs_topwins_dict(bin_size)
	while total_bet < daily_bet and time_remaining > 0:
		tmp_total_bet = total_bet
		potential_contests = data_scrapping.get_potential_contests(s,['nhl'],[{"standard":1}],[3,5],[1,2,5,10,25],0.6,'7:00')
		print potential_contests
		total_bet = total_bet + data_scrapping.enter_best_contests(s,session_id,'NHL',(daily_bet - total_bet),potential_contests,time_remaining,wins_data,bin_size)
		time.sleep(60)
		time_remaining = Ugen.get_time_remain('17:00')
	fdo.end_fanduel_session(s)
	return total_bet
예제 #3
0
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
예제 #4
0
def run_program(sport_list, update_model_interval, max_bet):
    FDSession = fdo.FDSession()
    current_bet = 0
    #last contest_time = get_last_contest_time() - return last time for latest contest tonight
    run_time = 1000
    while current_bet <= max_bet:
        if run_time > update_model_interval:
            contest_rosters = build_contest_rosters(FDSession, sport_list)
            run_time = 10
        else:
            for contest_id, roster in contest_rosters.iteritems():
                contest_list = FDSession.fanduel_api_data(
                    "https://api.fanduel.com/contests?fixture_list=" +
                    contest_id)['contests']
                for contest in contest_list:
                    enter, entered_contest = contest_entry_decider(
                        FDSession, contest, roster)
                    if enter == True:
                        entered_contest['model_confidence'] = roster[
                            'confidence']
                        entered_contest['slate_player_count'] = roster[
                            'slate_player_count']
                        entered_contest['timestamp'] = str(datetime.now())
                        entered_contest['sport'] = roster['class'].sport
                        print 'entering contest'
                        os.system('pause')
                        if FDSession.enter_contest(contest['entries']['_url'],
                                                   roster['roster'],
                                                   entered_contest) == True:
                            current_bet = current_bet + contest['entry_fee']
                            print 'current bet=' + str(current_bet)
        print 'loop'
        os.system('pause')
예제 #5
0
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])])
예제 #6
0
def run_enter_best_contests(daily_bet, bin_size):
    s, session_id = fdo.get_fanduel_session()
    total_bet = 0
    time_remaining = Ugen.get_time_remain('17:00')
    wins_data = build_pWins_vs_topwins_dict(bin_size)
    while total_bet < daily_bet and time_remaining > 0:
        tmp_total_bet = total_bet
        potential_contests = data_scrapping.get_potential_contests(
            s, ['nhl'], [{
                "standard": 1
            }], [3, 5], [1, 2, 5, 10, 25], 0.6, '7:00')
        print potential_contests
        total_bet = total_bet + data_scrapping.enter_best_contests(
            s, session_id, 'NHL', (daily_bet - total_bet), potential_contests,
            time_remaining, wins_data, bin_size)
        time.sleep(60)
        time_remaining = Ugen.get_time_remain('17:00')
    fdo.end_fanduel_session(s)
    return total_bet
예제 #7
0
def hist_FD_contest_salaries():
    todays_date = time.strftime("%Y-%m-%d")
    table = 'hist_fanduel_data'
    recordset = dbo.get_table_last_row(table, 'Date')
    if str(recordset[0][1]) == todays_date:
        print "hist_fd_contest_salares: salaries already historized in %s for today " % table
        time.sleep(5)
        return
    s, session_id = fdo.get_fanduel_session()
    contest_dict = fdo.get_FD_contests(s)
    sports_list = ['mlb', 'nba', 'nhl',
                   'nfl']  #pick this option if you wanna historize all sports
    #sports_list=['mlb','nba']
    for sport in sports_list:
        print sport
        sport_contest_dict = (x for x in contest_dict if x['sport'] == sport)
        test_dict_case = (x for x in contest_dict if x['sport'] == sport
                          )  #assign duplicate var to avoid list mutation
        if len(list(test_dict_case)
               ) > 0:  #test if there are contests for the sport
            historized_contests = []
            ContestID = ''
            rw = 1
            for contest in sport_contest_dict:  #loop through each for given sport
                Url = 'https://www.fanduel.com/e/Game' + contest['entryURL'][
                    contest['entryURL'].find('Game\\') + 5:]
                # print contest['startString']
                if contest['gameId'] not in historized_contests and len(
                        contest['startString']
                ) < 14 and contest['entryURL'].find(
                        'accept_public_challenge'
                ) == -1:  #check for contests at other times
                    print 'now historizing %s contest#: %d' % (
                        sport, contest['gameId'])
                    hist_FD_playerdata(sport.upper(), Url, contest['gameId'])
                    print '%s contest#: %d historized succesfully' % (
                        sport, contest['gameId'])
                    historized_contests.append(contest['gameId'])
    fdo.end_fanduel_session(s)
    return
예제 #8
0
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])])
예제 #9
0
def todays_lineups(sport_list):
    FDSession = fdo.FDSession()
    contest_rosters = main.build_contest_rosters(FDSession, sport_list)
    #write to csv!
    return
예제 #10
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