Created
August 9, 2013 17:27
-
-
Save bsoist/6195449 to your computer and use it in GitHub Desktop.
Ranking NFL players based on Fanium rules. See http://bsoist.smallpict.com/2013/08/09/rankingNflPlayersUsingFaniumRules for more information.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib, re | |
from htmldom import htmldom | |
from operator import itemgetter | |
index, playerinfo = 0, [] | |
PASSING_YARDS = 0 | |
PASSING_TDS = 1 | |
INT = 2 | |
RUSHING_YARDS = 4 | |
RUSHING_TDS = 5 | |
RECEPTIONS = 6 | |
RECEIVING_YARDS = 7 | |
RECEIVING_TDS = 8 | |
def getPlayers(n): | |
for i in range(n): | |
print players.next() | |
c = httplib.HTTPConnection('games.espn.go.com') | |
for i in range(33): | |
index = i*40 | |
c.request('GET','/ffl/tools/projections?startIndex=%s' % index) | |
playerinfo += [[td.getText() for td in row.children] for row in htmldom.HtmlDom().createDom(c.getresponse().read()).find('.pncPlayerRow').toList()] | |
players = [] | |
for player in playerinfo: | |
parts = player[1].split(',') | |
name, rest = re.sub('[\t\r\n*]','',parts[0]), re.sub('[\t\r\n*]','',parts[-1]) | |
restparts = rest.split(' ') | |
team, pos = re.sub('[\t\r\n*]','',restparts[0]), re.sub('[\t\r\n*]','',restparts[-1]) | |
try: | |
player = map(int,player[3:]) | |
except: | |
continue | |
points = player[RECEPTIONS] + (player[PASSING_YARDS] / 20 ) + (player[RUSHING_YARDS] / 5 ) + (player[RECEIVING_YARDS] / 5) + ((player[PASSING_TDS] + player[RUSHING_TDS] + player[RECEIVING_TDS] ) * 7 ) - (player[INT] * 3) | |
players.append((name,team,pos,points)) | |
players = reversed(sorted([player for player in players if player[-1]],key=itemgetter(3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment