<commit_before>from settings import *
import simple_crypto
from selenium import webdriver
import cookielib
from BeautifulSoup import BeautifulSoup
from soupselect import select
import time

class YahooFantasyFootball(object):
	"""Collects information from Yahoo Fantasy Football"""
	def __init__(self, league_url):
		super(YahooFantasyFootball, self).__init__()
		self.league_url = league_url

		self.phantom = webdriver.PhantomJS()
		self.phantom.set_window_size(1280, 1024)		

		self.last_refresh = None	

	def process(self):
		if self.last_refresh is None:
			raise Exception('Cannot process data prior to retrieving it (with refresh())')

		scores = {}
		matchups = []
		b = BeautifulSoup(self.html)
		for row in select(b, 'ul.Bdrbot li'):
			matchup = []
			for player in select(row, 'div.Grid-h-mid'):
				score = select(player, 'div.Fz-lg')[0].getText()
				projected = select(player, 'div.F-shade')[0].getText()
				name = select(player, 'div.Fz-sm a')[0].getText()
				scores[name] = {'score': score, 'projected': projected}
				matchup.append(name)
			matchups.append(matchup)

		self.scores = scores
		self.matchups = matchups

		standings = []
		cell_order = ('rank', 'name', 'record', 'points', 'streak', 'waiver', 'moves')
		for row in select(b, 'table#standingstable tbody tr'):
			record = {}
			for (i, cell) in enumerate(select(row, 'td')):
				record[cell_order[i]] = cell.getText()
			standings.append(record)

		self.standings = standings

	def refresh(self):
		
		self.phantom.get(self.league_url)
		
		if ('login' in self.phantom.title.lower()) or ('sign in to yahoo' in self.phantom.title.lower()):
		
			submit_control = None
			
			for e in self.phantom.find_elements_by_tag_name('input'):
				
				# login
				if e.get_attribute('name') in ('login', 'id'):
					e.send_keys(YAHOO_USERNAME)
				
				# password
				if e.get_attribute('name') in ('passwd', 'password'):
					e.send_keys(simple_crypto.decrypt(YAHOO_PASSWORD))
				
				# 'remember me'
				if e.get_attribute('name') in ('persistent',):
					if e.get_attribute('value')=='y':
						self.phantom.get_element_by_id('pLabelC').click()
				
				# mobile login form?
				if e.get_attribute('name') in ('.save', '__submit'):
						submit_control = e

			# ugh it's a <button>
			if submit_control is None:
				for e in self.phantom.find_elements_by_tag_name('button'):
					if e.get_attribute('name') in ('.save', '__submit'):
						submit_control = e

			if submit_control is not None:
				submit_control.click()
				time.sleep(5)
			else:
				raise Exception('Submission control not found!')

		self.last_refresh = time.time()
		self.html = self.phantom.page_source
	

	def get_score_differential(self, player):
		opponent = None
		for m in self.matchups:
			for (i, p) in enumerate(m):
				if p == player:
					opponent = m[(i+1) % len(m)]		
		
		if opponent is None:
			raise Exception('Could not find player in matchups')

		return int(self.scores[player]['score']) - int(self.scores[opponent]['score'])


if __name__ == '__main__':
	y = YahooFantasyFootball(YAHOO_LEAGUE_URL)
	y.refresh()	
	y.process()
<commit_msg>adding support for the bonus field yahoo has thrown into the UI<commit_after>from settings import *
import simple_crypto
from selenium import webdriver
import cookielib
from BeautifulSoup import BeautifulSoup
from soupselect import select
import time

class YahooFantasyFootball(object):
	"""Collects information from Yahoo Fantasy Football"""
	def __init__(self, league_url):
		super(YahooFantasyFootball, self).__init__()
		self.league_url = league_url

		self.phantom = webdriver.PhantomJS()
		self.phantom.set_window_size(1280, 1024)		

		self.last_refresh = None	

	def process(self):
		if self.last_refresh is None:
			raise Exception('Cannot process data prior to retrieving it (with refresh())')

		scores = {}
		matchups = []
		b = BeautifulSoup(self.html)
		for row in select(b, 'ul.Bdrbot li'):
			matchup = []
			for player in select(row, 'div.Grid-h-mid'):
				score = select(player, 'div.Fz-lg')[0].getText()
				projected = select(player, 'div.F-shade')[0].getText()
				name = select(player, 'div.Fz-sm a')[0].getText()
				scores[name] = {'score': score, 'projected': projected}
				matchup.append(name)
			matchups.append(matchup)

		self.scores = scores
		self.matchups = matchups

		standings = []
		cell_order = ('rank', 'name', 'record', 'points', 'points_against', 'streak', 'waiver', 'moves')
		for row in select(b, 'table#standingstable tbody tr'):
			record = {}
			for (i, cell) in enumerate(select(row, 'td')):
				record[cell_order[i]] = cell.getText()
			standings.append(record)

		self.standings = standings

	def refresh(self):
		
		self.phantom.get(self.league_url)
		
		if ('login' in self.phantom.title.lower()) or ('sign in to yahoo' in self.phantom.title.lower()):
		
			submit_control = None
			
			for e in self.phantom.find_elements_by_tag_name('input'):
				
				# login
				if e.get_attribute('name') in ('login', 'id'):
					e.send_keys(YAHOO_USERNAME)
				
				# password
				if e.get_attribute('name') in ('passwd', 'password'):
					e.send_keys(simple_crypto.decrypt(YAHOO_PASSWORD))
				
				# 'remember me'
				if e.get_attribute('name') in ('persistent',):
					if e.get_attribute('value')=='y':
						self.phantom.get_element_by_id('pLabelC').click()
				
				# mobile login form?
				if e.get_attribute('name') in ('.save', '__submit'):
						submit_control = e

			# ugh it's a <button>
			if submit_control is None:
				for e in self.phantom.find_elements_by_tag_name('button'):
					if e.get_attribute('name') in ('.save', '__submit'):
						submit_control = e

			if submit_control is not None:
				submit_control.click()
				time.sleep(5)
			else:
				raise Exception('Submission control not found!')

		self.last_refresh = time.time()
		self.html = self.phantom.page_source
	

	def get_score_differential(self, player):
		opponent = None
		for m in self.matchups:
			for (i, p) in enumerate(m):
				if p == player:
					opponent = m[(i+1) % len(m)]		
		
		if opponent is None:
			raise Exception('Could not find player in matchups')

		return int(self.scores[player]['score']) - int(self.scores[opponent]['score'])


if __name__ == '__main__':
	y = YahooFantasyFootball(YAHOO_LEAGUE_URL)
	y.refresh()	
	y.process()

{'fraction_non_alphanumeric': 0.13873845173622174, 'fraction_numerical': 0.00414144632048423, 'mean_word_length': 3.8337182448036953, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '737149', 'n_tokens_mistral': 2557, 'n_tokens_neox': 2083, 'n_words': 518}