Esempio n. 1
0
def get_team_odds(sport):
    url="http://www.oddsshark.com/"+sport+"/odds/fullgame/moneyline"
    content= urllib2.urlopen(url).read()
    soup = BeautifulSoup(content)
    i=1 #counter for cells in excel
    mlb_map=Ugen.excel_mapping("Team Map",7,6)
    nhl_map=Ugen.excel_mapping("Team Map",3,1)
    odds_list={}
    date_raw=soup.find("div",{"class":"time type"}).get_text().split()
    date=date_raw[0]+' '+date_raw[1][0]+date_raw[1][1] #Ian: first date in the table. if any of the row's dates do not equal this then it wont get the odds for that game because its on a diff day
    for z in range(0,2,1):
        if z==0:
            row_type='even'
        elif z==1:
            row_type='odd'
        for row in soup.findAll("div",{"class":"odds-row odds-row-moneyline "+row_type}): 
            teams=row.findAll("div",{ "class":"first teams type" })
            teams_list=teams[0].get_text().split() #two word teams get split into different elements here, teams_list=['New','Jersey','Calgary']
            j=0  
            for z in range(0,2,1):
                if get_teamname_exceptions(teams_list[j],sport):
                    if z==0:
                        if teams_list[j]=='Chi' and teams_list[j+1]=='White':
                            team1=teams_list[j]+ ' ' + teams_list[j+1]+ ' ' + teams_list[j+2]
                            j=j+3
                        else:
                            team1=teams_list[j]+ ' ' + teams_list[j+1]
                            j=j+2
                    elif z==1:
                        if teams_list[j]=='Chi' and teams_list[j+1]=='White':
                            team2=teams_list[j]+ ' ' + teams_list[j+1]+ ' ' + teams_list[j+2]
                        else:
                            team2=teams_list[j]+ ' ' + teams_list[j+1]
                else:
                    if z==0:
                        team1=teams_list[j]
                        j=j+1
                    elif z==1:
                        team2=teams_list[j]
            row_date_raw=row.find("div",{"class":"time type"}).get_text().split()
            row_date=row_date_raw[0]+' '+row_date_raw[1][0]+row_date_raw[1][1]
            if row_date==date: #Ian: check if current games date is equal to the date in the first row
                moneyline1=row.findAll("div",{"class":"book moneyline book-"+"1"})[0].get_text().split() #for now just do opening odds
                if sport=='MLB':
                    team_map = mlb_map
                elif sport=='NHL':
                    team_map=nhl_map
                else:
                    print 'team map does not exist for entered sport: %s' % sport
                    #return
                if moneyline1:
                    odds_list[team_map[team1]]=round(odds_to_prob(moneyline1[0],'American Moneyline'),2)#Cole:incorporated mapping to change city name to NHL team name
                    odds_list[team_map[team2]]=round(odds_to_prob(moneyline1[1],'American Moneyline'),2)
                    #odds_list[team1]=round(odds_to_prob(moneyline1[0],'American Moneyline'),2)
                    #odds_list[team2]=round(odds_to_prob(moneyline1[1],'American Moneyline'),2)
            i=i+1
    # Cell("Output",1,1).value=odds_list
    return [odds_list,date]
Esempio n. 2
0
def build_lineup_dict():
    rw = 2
    if Cell('Parameters', 'clLineupsCache').value == None:
        team_map = Ugen.excel_mapping('Team Map', 1, 2)
        team_lineups_dict = {}
        for team in team_map.keys():
            roster_url = 'http://www2.dailyfaceoff.com/teams/lines/' + str(
                team_map[team]) + '/'
            response = urllib2.urlopen(roster_url)
            shtml = response.read()
            soup = BeautifulSoup(shtml)
            lineups = soup.findAll('td')
            lines = []
            line = []
            line_id = 1
            for lineup in lineups:
                if lineup.get('id') == 'G1':
                    lines.append(line)
                    break
                elif lineup.get('id')[-1] == line_id:
                    try:
                        line.append(str(lineup.get_text()).strip())
                    except:
                        print lineup.get_text()
                else:
                    if line:
                        lines.append(line)
                    line = []
                    try:
                        line.append(str(lineup.get_text()).strip())
                    except:
                        print lineup.get_text()
                    line_id = lineup.get('id')[-1]
            team_lineups_dict[team] = lines
        Cell('Parameters', 'clLineupsCache').value = team_lineups_dict
    else:
        team_lineups_dict = ast.literal_eval(
            Cell('Parameters', 'clLineupsCache').value)
    return team_lineups_dict
Esempio n. 3
0
def build_lineup_dict():
	rw = 2
	if Cell('Parameters','clLineupsCache').value == None:
		team_map = Ugen.excel_mapping('Team Map',1,2)
		team_lineups_dict = {}
		for team in team_map.keys():
			roster_url = 'http://www2.dailyfaceoff.com/teams/lines/' + str(team_map[team]) +'/'
			response = urllib2.urlopen(roster_url)
			shtml = response.read()
			soup = BeautifulSoup(shtml)
			lineups = soup.findAll('td')
			lines = []
			line = []
			line_id = 1
			for lineup in lineups:
				if lineup.get('id') == 'G1':
					lines.append(line)
					break
				elif lineup.get('id')[-1] == line_id:
 					try:
 						line.append(str(lineup.get_text()).strip())
 					except:
 						print lineup.get_text()
				else:
					if line:
						lines.append(line)
					line = []
 					try:
 						line.append(str(lineup.get_text()).strip())
 					except:
 						print lineup.get_text()
					line_id = lineup.get('id')[-1]			
			team_lineups_dict[team] = lines
		Cell('Parameters','clLineupsCache').value = team_lineups_dict
	else:
		team_lineups_dict = ast.literal_eval(Cell('Parameters','clLineupsCache').value)
	return team_lineups_dict
Esempio n. 4
0
def get_team_odds(sport):
    url = "http://www.oddsshark.com/" + sport + "/odds/fullgame/moneyline"
    content = urllib2.urlopen(url).read()
    soup = BeautifulSoup(content)
    i = 1  #counter for cells in excel
    mlb_map = Ugen.excel_mapping("Team Map", 7, 6)
    nhl_map = Ugen.excel_mapping("Team Map", 3, 1)
    odds_list = {}
    date_raw = soup.find("div", {"class": "time type"}).get_text().split()
    date = date_raw[0] + ' ' + date_raw[1][0] + date_raw[1][
        1]  #Ian: first date in the table. if any of the row's dates do not equal this then it wont get the odds for that game because its on a diff day
    for z in range(0, 2, 1):
        if z == 0:
            row_type = 'even'
        elif z == 1:
            row_type = 'odd'
        for row in soup.findAll(
                "div", {"class": "odds-row odds-row-moneyline " + row_type}):
            teams = row.findAll("div", {"class": "first teams type"})
            teams_list = teams[0].get_text().split(
            )  #two word teams get split into different elements here, teams_list=['New','Jersey','Calgary']
            j = 0
            for z in range(0, 2, 1):
                if get_teamname_exceptions(teams_list[j], sport):
                    if z == 0:
                        if teams_list[j] == 'Chi' and teams_list[j +
                                                                 1] == 'White':
                            team1 = teams_list[j] + ' ' + teams_list[
                                j + 1] + ' ' + teams_list[j + 2]
                            j = j + 3
                        else:
                            team1 = teams_list[j] + ' ' + teams_list[j + 1]
                            j = j + 2
                    elif z == 1:
                        if teams_list[j] == 'Chi' and teams_list[j +
                                                                 1] == 'White':
                            team2 = teams_list[j] + ' ' + teams_list[
                                j + 1] + ' ' + teams_list[j + 2]
                        else:
                            team2 = teams_list[j] + ' ' + teams_list[j + 1]
                else:
                    if z == 0:
                        team1 = teams_list[j]
                        j = j + 1
                    elif z == 1:
                        team2 = teams_list[j]
            row_date_raw = row.find("div", {
                "class": "time type"
            }).get_text().split()
            row_date = row_date_raw[0] + ' ' + row_date_raw[1][
                0] + row_date_raw[1][1]
            if row_date == date:  #Ian: check if current games date is equal to the date in the first row
                moneyline1 = row.findAll(
                    "div",
                    {"class": "book moneyline book-" + "1"
                     })[0].get_text().split()  #for now just do opening odds
                if sport == 'MLB':
                    team_map = mlb_map
                elif sport == 'NHL':
                    team_map = nhl_map
                else:
                    print 'team map does not exist for entered sport: %s' % sport
                    #return
                if moneyline1:
                    odds_list[team_map[team1]] = round(
                        odds_to_prob(moneyline1[0], 'American Moneyline'), 2
                    )  #Cole:incorporated mapping to change city name to NHL team name
                    odds_list[team_map[team2]] = round(
                        odds_to_prob(moneyline1[1], 'American Moneyline'), 2)
                    #odds_list[team1]=round(odds_to_prob(moneyline1[0],'American Moneyline'),2)
                    #odds_list[team2]=round(odds_to_prob(moneyline1[1],'American Moneyline'),2)
            i = i + 1
    # Cell("Output",1,1).value=odds_list
    return [odds_list, date]