You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

438 lines
13 KiB
Python

#!/usr/bin/python3
import pandas
import re
class FantasyProsProjections:
# TODO REM need to add week # and scoring.
PROJ_URL = 'https://www.fantasypros.com/nfl/projections/{pos}.php'
ROS_URL = 'https://www.fantasypros.com/nfl/rankings/ros-ppr-overall.php'
PLAYER_URL = ('https://www.fantasypros.com/nfl/projections/{name}.php?' +
'week={week}')
# TEMPORARY CONSTANT TODO
WEEK_NUM = 1
def __init__(self, pos):
self.pos = pos
self.week = self.WEEK_NUM
self.data = {}
self._get_proj_data()
def get_projection(self, first_name, last_name):
for fpros_name, proj in self.data.items():
if (re.match(f'.*{first_name}.*', fpros_name) and
re.match(f'.*{last_name}.*', fpros_name)):
return proj
# If we got here then we couldn't find the name. This can happen if the
# player is out for the week, therefore we look.... TODO
site_proj = self._get_proj_from_player_site(
f'{first_name} {last_name}')
# TODO In the future maybe we can keep IGNORED_PLAYERS empty and
# populate it based on these if statements.
# if site_proj > 0:
# print(f'DEBUG: Projection from site for {first_name} ' +
# f'{last_name} was {site_proj}.')
# if site_proj < 2:
# print(f'IGNORE: {first_name} {last_name}XXX')
return site_proj
def _get_proj_from_player_site(self, name):
if name in self.IGNORED_PLAYERS:
return 0.0
elif name in self.FPROS_NAME_TO_URL_PARAM:
name_param = self.FPROS_NAME_TO_URL_PARAM[name]
else:
print(f'DEBUG: Getting projection for {name} from player site.')
# Convert the name to our URL arg by:
# - Strip 'II' 'III' at the end of the name.
# - Replace spaces with '-'s.
# - Convert to lowercase.
name_param = (re.sub(r' [IV]+$', '', name)
.replace(' ', '-')
.replace('.', '')
.replace('\'', '')
.lower())
name_param = re.sub(r'-[js]r$', '', name_param)
# TODO REM STARTHERE We still need to figure out how to detect when
# this fails....
html = pandas.read_html(self.PLAYER_URL.format(name=name_param,
week=self.week))
proj_points = html[0]['Points'].get(0)
if (isinstance(proj_points, str) and
re.match("^Player does not have", proj_points)):
return 0.0
return proj_points
def _get_proj_data(self):
html = pandas.read_html(self.PROJ_URL.format(pos=self.pos))
data = html[0]
drop_keys = []
for key in data.keys():
if isinstance(data.keys(), pandas.core.indexes.multi.MultiIndex):
keyname = key[1]
else:
keyname = key
if keyname != 'Player' and keyname != 'FPTS':
drop_keys.append(key)
data2 = data.drop(drop_keys, axis=1)
for elem in data2.itertuples():
# self.data.append(
# FantasyProsPlayerProjection(
# name=sub(r' \w+$', '', elem[1]),
# proj_points=elem[2]))
name = ''
if self.pos == 'dst':
name = elem[1]
else:
name = re.sub(r' \w+$', '', elem[1])
self.data[name] = elem[2]
# def _get_ros_data(self):
# These players are ignored.
#
# TODO only Cal Adomitis do we really want to ignore. We ignore the other
# to speed things up and to potentially avoid rate limiting (if there is
# any) for fpros.
# IGNORED_PLAYERS = {
# 'Cal Adomitis',
# 'Jack Coco',
# 'Damarea Crockett', # This guy has no projection and doesn't work,
# # not sure why.
# 'Bisi Johnson',
# 'Brian Robinson Jr.',
# 'Cameron Batson',
# 'Drew Ogletree',
# 'Dylan Parham',
# 'Gerrit Prince',
# 'Johnny Johnson III',
# 'Kevin Rader',
# 'P.J. Walker',
# 'Pierre Strong Jr.',
# 'Ricky Person Jr.',
# 'Ronald Jones II',
# 'Scotty Miller',
# 'Spencer Brown',
# 'Troy Hairston',
# 'Velus Jones Jr.',
# 'Willie Johnson'
# }
# # Purposely not ignoring Gabe Davis because he's projected to score
# # points.
IGNORED_PLAYERS = {
'Mike Evans',
'Deshaun Watson',
'DeAndre Hopkins',
'Jameson Williams',
'Tyrion Davis-Price',
'Zach Wilson',
'Kenneth Walker III',
'Sam Darnold',
'Colt McCoy',
'Blaine Gabbert',
'Gus Edwards',
'Jeff Driskel',
'Tim Boyle',
'Giovani Bernard',
'Mason Rudolph',
'Elijah Mitchell',
'Brian Robinson Jr.',
'Ryan Griffin',
'Danny Etling',
'Kenjon Barner',
'Patrick Laird',
'Kylin Hill',
'Tyler Goodson',
'Bailey Zappe',
'Ben Mason',
'Ricky Person Jr.',
'Tyler Badie',
'J.J. Taylor',
'Kevin Harris',
'Shane Buechele',
'Chris Oladokun',
'Sam Ehlinger',
'D\'vonte Price',
'Phillip Lindsay',
'Kellen Mond',
'Josh Rosen',
'Jeremy McNichols',
'Anthony McFarland Jr.',
'Jason Huntley',
'John Kelly Jr.',
'P.J. Walker',
'Matt Corral',
'Jacob Eason',
'Jake Luton',
'John Lovett',
'Latavius Murray',
'Nathan Peterman',
'Darrynton Evans',
'Darius Anderson',
'Royce Freeman',
'Gerrid Doaks',
'Skylar Thompson',
'Matt Barkley',
'John Lovett',
'ZaQuandre White',
'Raheem Blackshear',
'Duke Johnson',
'David Blough',
'Ty Chandler',
'Bryant Koback',
'Greg Bell',
'Jermar Jefferson',
'Jason Cabinda',
'Chris Streveler',
'Jake Browning',
'Nick Bawden',
'Zonovan Knight',
'Trayveon Williams',
'Elijah Holyfield',
'Chase Garbers',
'Logan Woodside',
'Sincere McCormick',
'Austin Walter',
'Trenton Cannon',
'Sam Howell',
'Ian Book',
'Jaret Patterson',
'Kennedy Brooks',
'E.J. Perry',
'Easton Stick',
'Mekhi Sargent',
'Larry Rountree III',
'Jarrett Guarantano',
'Bryce Perkins',
'Jonathan Ward',
'Kyren Williams',
'Ronnie Rivers',
'Sean Mannion',
'Darwin Thompson',
'Damien Williams',
'B.J. Baylor',
'Trey Lance',
'Josh Johnson',
'Damarea Crockett',
'Devine Ozigbo',
'Davis Webb',
'Sandro Platzgummer',
'Jashaun Corbin',
'Malik Davis',
'Qadree Ollison',
'Tre\'Quan Smith',
'Antoine Wesley',
'Deven Thompkins',
'Samori Toure',
'Travis Fulgham',
'Juwann Winfree',
'Slade Bolden',
'Makai Polk',
'Binjimen Victor',
'Ty Montgomery',
'Tyquan Thornton',
'Kristian Wilkerson',
'Laquon Treadwell',
'Lynn Bowden Jr.',
'Tre Nixon',
'Justyn Ross',
'Corey Coleman',
'Daurice Fountain',
'Jerrion Ealy',
'Cornell Powell',
'Ethan Fernea',
'Steven Sims Jr.',
'Calvin Austin III',
'Anthony Miller',
'Cody White',
'Michael Woods II',
'Jakeem Grant Sr.',
'Isaiah Weston',
'Chester Rogers',
'Mike Harley Jr.',
'Daylen Baldwin',
'Andre Roberts',
'C.J. Saunders',
'Preston Williams',
'Derek Wright',
'Kawaan Baker',
'Rashid Shaheed',
'Kirk Merritt',
'N\'Keal Harry',
'Nsimba Webster',
'Isaiah Coulter',
'John Metchie III',
'Drew Estrada',
'Johnny Johnson III',
'Jalen Camp',
'Erik Ezukanma',
'Braylon Sanders',
'Freddie Swain',
'Marquez Stevenson',
'Tavon Austin',
'Isaiah Hodgins',
'Blake Proehl',
'Bisi Johnson',
'Thomas Hennigan',
'Travis Toivonen',
'Trishton Jackson',
'Dan Chisena',
'Tom Kennedy',
'Maurice Alexander',
'Denzel Mims',
'Rodney Adams',
'Irvin Charles',
'Tarik Black',
'Trenton Irwin',
'Kwamie Lassiter II',
'DJ Turner',
'Isaiah Zuber',
'Chris Lacy',
'Racey McMath',
'Dez Fitzpatrick',
'Mason Kinsey',
'Kyric McGowan',
'Alex Erickson',
'Marken Michel',
'Deon Cain',
'Devon Allen',
'Auden Tate',
'Kendric Pryor',
'Willie Johnson',
'Kevin Austin Jr.',
'Seth Williams',
'Jaylon Moore',
'Joe Reed',
'Michael Bandy',
'Jason Moore Jr.',
'Javon Wims',
'Jeff Cotton Jr.',
'Lance McCutcheon',
'J.J. Koski',
'Austin Trammell',
'Dareke Young',
'Cody Thompson',
'J.J. Arcega-Whiteside',
'Cade Johnson',
'Bo Melton',
'Calvin Ridley',
'Josh Ali',
'Frank Darby',
'Cameron Batson',
'Willie Snead IV',
'Malik Turner',
'Tay Martin',
'Jalen Virgil',
'Tim Patrick',
'Vyncint Smith',
'Darrius Shepherd',
'James Washington',
'Collin Johnson',
'Marcus Johnson',
'Kalil Pimpleton',
'Brandon Smith',
'Dontario Drummond',
'David Wells',
'Tyler Davis',
'Shaun Beyer',
'Jack Coco',
'Charlie Kolar',
'Jalen Wydermyer',
'Matt Sokol',
'Blake Bell',
'Jordan Franks',
'Kendall Blanton',
'James Winchester',
'Drew Ogletree',
'Jared Scott',
'Nikola Kalinic',
'Rodney Williams II',
'Jesse James',
'Miller Forristall',
'Zaire Mitchell-Paden',
'Colin Thompson',
'Josh Babicz',
'Lucas Krull',
'Zach Wood',
'J.P. Holtz',
'Patrick Scales',
'Chase Allen',
'Teagan Quitoriano',
'Mason Schreck',
'Adam Shaheen',
'Zach Davidson',
'Andrew DePaola',
'Nick Muse',
'Garrett Griffin',
'Lawrence Cager',
'Cal Adomitis',
'Clark Harris',
'Nick Bowers',
'Cole Fotheringham',
'Tommy Hudson',
'Thomas Odukoya',
'Kevin Rader',
'Curtis Hodges',
'Eli Wolf',
'Tyree Jackson',
'Dalton Keene',
'Gerrit Prince',
'Stone Smartt',
'Hunter Kampmoyer',
'Bernhard Seikovits',
'Jared Pinkney',
'Roger Carter Jr.',
'Tyler Mabry',
'Tyler Ott',
'Feleipe Franks',
'John FitzPatrick',
'MyCole Pruitt',
'Beau Brinkley',
'Tucker Fisk',
'Jordan Matthews',
'Troy Fumagalli',
'Greg Dulcich',
'Dominique Dafney',
'Austin Allen',
'Ian Bunting',
'Sean McKeon'
}
# All of these players don't have the expected url param.
# TODO Is this actually DRAFT_KINGS_NAME_TO_FPROS_URL_PARAM?
FPROS_NAME_TO_URL_PARAM = {
'Bisi Johnson': 'olabisi-johnson',
'Brian Robinson Jr.': 'brian-robinson-jr',
'Cameron Batson': 'cam-batson',
'Drew Ogletree': 'andrew-ogletree',
'Dylan Parham': 'dylan-parham-te',
'Gabe Davis': 'gabriel-davis',
'Gerrit Prince': 'gerrit-prince-te',
'Johnny Johnson III': 'johnny-johnson-iii',
'Kevin Rader': 'kevin-radar',
'P.J. Walker': 'phillip-walker',
'Pierre Strong Jr.': 'pierre-strong-jr',
'Ricky Person Jr.': 'ricky-person-jr',
'Ronald Jones II': 'ronald-jones-ii',
'Scotty Miller': 'scott-miller',
'Spencer Brown': 'spencer-brown-rb',
'Troy Hairston': 'troy-hairston-ii',
'Velus Jones Jr.': 'velus-jonesjr',
'Willie Johnson': 'willie-jackson'
}
class FantasyProsPlayerProjection:
def __init__(self, name, proj_points):
self.name = name
self.proj_points = proj_points
def __str__(self):
return str(self.__dict__)