Skip to content

Instantly share code, notes, and snippets.

@mattdodge
Created March 19, 2013 17:52
Show Gist options
  • Save mattdodge/5198428 to your computer and use it in GitHub Desktop.
Save mattdodge/5198428 to your computer and use it in GitHub Desktop.
A utility that hits TeamRankings and gets the matchup probabilities for each team in the NCAA tournament. You will need to hard-code (blech) all of the team IDs for now, I'm lazy
'''
Created on Mar 18, 2013
@author: Matt Dodge
'''
from bs4 import BeautifulSoup as BS
from httplib2 import Http
from urllib import urlencode
import json
west = {
1:624,
2:426,
3:574,
4:600,
5:431,
6:397,
7:633,
8:637,
9:553,
10:601,
11:516,
12:699,
13:496,
14:672,
15:385,
16:492
}
east = {
1:424,
2:636,
3:420,
4:630,
5:572,
6:666,
7:423,
8:388,
9:500,
10:602,
11:433,
12:400,
13:581,
14:527,
15:440,
16:464
}
south = {
1:604,
2:641,
3:697,
4:428,
5:532,
6:403,
7:573,
8:388,
9:632,
10:597,
11:422,
12:481,
13:1073,
14:687,
15:944,
16:595
}
midwest = {
1:411,
2:391,
3:425,
4:407,
5:598,
6:413,
7:554,
8:575,
9:606,
10:409,
11:621,
12:405,
13:586,
14:457,
15:569,
16:548
}
def getTeamProb(team1, team2):
h = Http()
resp, content = h.request(
'http://www.teamrankings.com/ncaa-tournament/matchups/?t1={0}&t2={1}&p=tournament-overview'.format(team1,team2),
'GET')
bb = BS(content)
tableRows = bb.select("table.big-text tbody tr")
total = 1
count = 0
for tableRow in tableRows:
total += float(tableRow.find('td').findNextSibling(text=None).contents[0][:-1])
count += 1
return total/count/100
if __name__ == '__main__':
l = midwest
o = dict()
for seed1 in l:
for seed2 in l:
if seed2 > seed1:
print 'Checking {0} against {1}'.format(l[seed1],l[seed2])
o[str(seed1) + ','+str(seed2)] = getTeamProb(l[seed1], l[seed2])
print json.dumps(o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment