def get_yahoo_user_info(): yahoo_helper = YahooHelper() if not 'yahoo_token' in session.keys(): return redirect( url_for('yahoo_oauth', next=url_for('get_yahoo_user_info') or None)) params = {'use_login': '******', 'game_key': 'nfl'} resp, content = get_yahoo_api_data('users/' + 'games/leagues', session['yahoo_token'][0], session['yahoo_token'][1], extras=params) if resp.status == 401: return redirect( url_for('yahoo_oauth', next=url_for('get_yahoo_user_info') or None)) data, resp = content, resp #yahoo_helper.import_json_data(content, get='user') #processed_data = yahoo_helper.return_data() return render_template( 'yahoo.html', what_data='user', #league_id = processed_data[0], #user_guid = processed_data[1], data=data, resp=resp)
def _internal_get_team_info(self): assert self.token_1 is not None assert self.token_2 is not None assert self.yahoo_league_key is not None resp, content = get_yahoo_api_data('league/' + self.yahoo_league_key + '/teams', self.token_1, self.token_2) print '%s API_CALL: GET_TEAM_INFO. LEAGUE_KEY %s' % (resp['date'], self.yahoo_league_key) print resp.reason, '\n' self.inc_api_counter() return resp, content
def _internal_get_players_data(self, week, team_key): assert self.token_1 is not None assert self.token_2 is not None param = {'week': week } resp, content = get_yahoo_api_data('team/' + team_key + '/roster/players', self.token_1, self.token_2, extras=param) print "\n" print '%s API_CALL: GET_PLAYERS_DATA. TEAM_KEY:%s WEEK:%s' % (resp['date'], team_key, week) print resp.reason self.inc_api_counter() return resp, content
def _internal_get_user_info(self): assert self.token_1 is not None assert self.token_2 is not None params = { 'use_login':'******', 'game_key':'nfl' } resp, content = get_yahoo_api_data('users/' + 'games/leagues', self.token_1, self.token_2, extras=params) print '%s API_CALL: GET_USER_INFO.' % (resp['date']) print resp.reason, '\n' print resp self.inc_api_counter() return resp, content
def _internal_get_team_info(self): assert self.token_1 is not None assert self.token_2 is not None assert self.yahoo_league_key is not None resp, content = get_yahoo_api_data( 'league/' + self.yahoo_league_key + '/teams', self.token_1, self.token_2) print '%s API_CALL: GET_TEAM_INFO. LEAGUE_KEY %s' % ( resp['date'], self.yahoo_league_key) print resp.reason, '\n' self.inc_api_counter() return resp, content
def _internal_get_team_stats(self, week): assert self.token_1 is not None assert self.token_2 is not None assert self.yahoo_league_key is not None # the week parameter should be passed in or caculated by the function. params = {'week': week } resp, content = get_yahoo_api_data('league/' + self.yahoo_league_key + '/scoreboard', self.token_1, self.token_2 ,extras=params) print '%s API_CALL: GET_TEAM_STATS. LEAGUE_KEY:%s WEEK:%s' % (resp['date'], self.yahoo_league_key, week) print resp.reason, '\n' self.inc_api_counter() return resp, content
def _internal_get_user_info(self): assert self.token_1 is not None assert self.token_2 is not None params = {'use_login': '******', 'game_key': 'nfl'} resp, content = get_yahoo_api_data('users/' + 'games/leagues', self.token_1, self.token_2, extras=params) print '%s API_CALL: GET_USER_INFO.' % (resp['date']) print resp.reason, '\n' print resp self.inc_api_counter() return resp, content
def do_the_call(list_of_team_keys, week): list_of_returned_content = list() week = str(week) params = { 'week': week } for team_key in list_of_team_keys: resp, content = get_yahoo_api_data('team/' + team_key + '/roster/players', self.token_1, self.token_2, extras=params) print "\n" print '%s API_CALL: GET_ALL_PLAYERS_DATA. TEAM_KEY:%s WEEK:%s' % (resp['date'], team_key, week) print resp.reason self.inc_api_counter() list_of_returned_content.append(content) return list_of_returned_content
def do_the_callz(list_of_team_keys, week): list_of_returned_content = list() week = str(week) params = {'type':'week', 'week':week} # take each team_key and make API call. for team_key in list_of_team_keys: resp, content = get_yahoo_api_data("team/" + team_key + "/roster/players/stats", self.token_1, self.token_2, extras=params) print '%s API_CALL: GET_PLAYER_STATS_FOR_WEEK. TEAM_KEY:%s WEEK:%s' % (resp['date'], team_key, week) print resp.reason, "\n" self.inc_api_counter() # append each returned JSON to a list. list_of_returned_content.append(content) return list_of_returned_content
def _internal_get_players_data(self, week, team_key): assert self.token_1 is not None assert self.token_2 is not None param = {'week': week} resp, content = get_yahoo_api_data('team/' + team_key + '/roster/players', self.token_1, self.token_2, extras=param) print "\n" print '%s API_CALL: GET_PLAYERS_DATA. TEAM_KEY:%s WEEK:%s' % ( resp['date'], team_key, week) print resp.reason self.inc_api_counter() return resp, content
def _internal_get_team_stats(self, week): assert self.token_1 is not None assert self.token_2 is not None assert self.yahoo_league_key is not None # the week parameter should be passed in or caculated by the function. params = {'week': week} resp, content = get_yahoo_api_data('league/' + self.yahoo_league_key + '/scoreboard', self.token_1, self.token_2, extras=params) print '%s API_CALL: GET_TEAM_STATS. LEAGUE_KEY:%s WEEK:%s' % ( resp['date'], self.yahoo_league_key, week) print resp.reason, '\n' self.inc_api_counter() return resp, content
def do_the_call(list_of_team_keys, week): list_of_returned_content = list() week = str(week) params = {'week': week} for team_key in list_of_team_keys: resp, content = get_yahoo_api_data('team/' + team_key + '/roster/players', self.token_1, self.token_2, extras=params) print "\n" print '%s API_CALL: GET_ALL_PLAYERS_DATA. TEAM_KEY:%s WEEK:%s' % ( resp['date'], team_key, week) print resp.reason self.inc_api_counter() list_of_returned_content.append(content) return list_of_returned_content
def do_the_callz(list_of_team_keys, week): list_of_returned_content = list() week = str(week) params = {'type': 'week', 'week': week} # take each team_key and make API call. for team_key in list_of_team_keys: resp, content = get_yahoo_api_data("team/" + team_key + "/roster/players/stats", self.token_1, self.token_2, extras=params) print '%s API_CALL: GET_PLAYER_STATS_FOR_WEEK. TEAM_KEY:%s WEEK:%s' % ( resp['date'], team_key, week) print resp.reason, "\n" self.inc_api_counter() # append each returned JSON to a list. list_of_returned_content.append(content) return list_of_returned_content
def _get_player_fantasy_stats_for_week(self): """takes team key and week as a parameter and returns matchup points scored for that week, team should pass in weeks arg from views? """ # this stuff is only here to get it working self.params = { 'type': 'week', 'week':'8' } team_key = team_key = '314.l.1173612.t.8' #^^^ resp, content = get_yahoo_api_data('team/' + team_key + '/roster/players/stats', self.token_1, self.token_2, extras=self.params) print 'API_CALL: GET_PLAYER_STATS_FOR_WEEK. team_key:%s' % (team_key) # this should never happen anyways # take care of this condition in views. #if resp.status != 200: # raise Exception("resp.status != 200") self.inc_api_counter() return resp, content
def get_yahoo_user_info(): yahoo_helper = YahooHelper() if not 'yahoo_token' in session.keys(): return redirect(url_for('yahoo_oauth', next=url_for('get_yahoo_user_info') or None)) params = { 'use_login':'******', 'game_key':'nfl' } resp, content = get_yahoo_api_data('users/' + 'games/leagues', session['yahoo_token'][0], session['yahoo_token'][1], extras=params) if resp.status == 401: return redirect(url_for('yahoo_oauth', next=url_for('get_yahoo_user_info') or None)) data, resp = content, resp #yahoo_helper.import_json_data(content, get='user') #processed_data = yahoo_helper.return_data() return render_template('yahoo.html', what_data = 'user', #league_id = processed_data[0], #user_guid = processed_data[1], data = data, resp = resp )
def get_stats(): """get weekly fantasy scores by team""" yahoo_helper = YahooHelper() yahoo_api_caller = YahooAPICaller() yahoo_db_helper = Db_Helper() if not 'yahoo_token' in session.keys(): return redirect( url_for('yahoo_oauth', next=url_for('get_stats') or None)) ### !!!!!!! league_key = 'nfl.l.1173612' ### there should be a call to the database for league key here. token_1, token_2 = session['yahoo_token'][0], session['yahoo_token'][1] #yahoo_api_caller.load_keys(token_1=token_1, token_2=token_2) params = {'week': '9'} ## for current week resp, content = get_yahoo_api_data('league/' + league_key + '/scoreboard', session['yahoo_token'][0], session['yahoo_token'][1], extras=params) if resp.status == 401: return redirect( url_for('yahoo_oauth', next=url_for('get_stats') or None)) yahoo_helper.import_json_data(content, get='team_stats') processed_data = yahoo_helper.return_data() #<== stats_dict returned here yahoo_db_helper.brians_import_team_stats( processed_data) #<== stats_dict being parsed # # SHOULD MAKE DB CALLS HERE TO PULL DATA NOW. # return render_template('yahoo.html', what_data='stats', resp=resp, processed_data=processed_data, content=content)
def yahoo_get_team(): '''get own fantasy team roster''' if not 'yahoo_token' in session.keys(): return redirect( url_for('yahoo_oauth', next=url_for('yahoo_get_team') or None)) yahoo_parser = YahooHelper() yahoo_caller = YahooAPICaller() yahoo_db_helper = Db_Helper() league_id = yahoo_db_helper.return_league_id(session['user_id']) league_key = '175.l.' + str(league_id) #params = { 'use_login':'******', 'game_key':'nfl' } resp, content = get_yahoo_api_data('league/' + league_key + '/teams', session['yahoo_token'][0], session['yahoo_token'][1], extras=params) if resp.status == 401: return redirect( url_for('yahoo_oauth', next=url_for('yahoo_get_team') or None)) processed_data = content data = "" return render_template('yahoo.html', what_data='test', resp=resp, processed_data=processed_data, data=data) # CALL YAHOO API HELPER # done but won't be able to display on the page the way im doing it. Compile yahoo_api_helper file on its own to debug. #yahoo_helper=YahooHelper() #yahoo_helper.import_json_data(content, get="teams") #yahoo_helper.return_data() # ['fantasy_content']['league'][1]['teams'][TEAM NUM] # to get data for all teams, need to get list of teams, then loop over [TEAM NUM] element '''
def yahoo_get_team(): '''get own fantasy team roster''' if not 'yahoo_token' in session.keys(): return redirect(url_for('yahoo_oauth', next=url_for('yahoo_get_team') or None)) yahoo_parser = YahooHelper() yahoo_caller = YahooAPICaller() yahoo_db_helper = Db_Helper() league_id = yahoo_db_helper.return_league_id(session['user_id']) league_key = '175.l.' + str(league_id) #params = { 'use_login':'******', 'game_key':'nfl' } resp, content = get_yahoo_api_data('league/' + league_key + '/teams', session['yahoo_token'][0], session['yahoo_token'][1], extras=params) if resp.status == 401: return redirect(url_for('yahoo_oauth', next=url_for('yahoo_get_team') or None)) processed_data = content data = "" return render_template('yahoo.html', what_data = 'test', resp = resp, processed_data = processed_data, data = data ) # CALL YAHOO API HELPER # done but won't be able to display on the page the way im doing it. Compile yahoo_api_helper file on its own to debug. #yahoo_helper=YahooHelper() #yahoo_helper.import_json_data(content, get="teams") #yahoo_helper.return_data() # ['fantasy_content']['league'][1]['teams'][TEAM NUM] # to get data for all teams, need to get list of teams, then loop over [TEAM NUM] element '''
def _get_player_fantasy_stats_for_week(self): """takes team key and week as a parameter and returns matchup points scored for that week, team should pass in weeks arg from views? """ # this stuff is only here to get it working self.params = {'type': 'week', 'week': '8'} team_key = team_key = '314.l.1173612.t.8' #^^^ resp, content = get_yahoo_api_data('team/' + team_key + '/roster/players/stats', self.token_1, self.token_2, extras=self.params) print 'API_CALL: GET_PLAYER_STATS_FOR_WEEK. team_key:%s' % (team_key) # this should never happen anyways # take care of this condition in views. #if resp.status != 200: # raise Exception("resp.status != 200") self.inc_api_counter() return resp, content
def yahoo_get_league(): '''get own fantasy team roster. need to add these extra fields into to postgresql database. goal: be able to query fantasy_league_id -> fantasy_team_id -> fantasy_players list''' if not 'yahoo_token' in session.keys(): return redirect( url_for('yahoo_oauth', next=url_for('yahoo_get_league') or None)) nfl_game_key = 'nfl' my_league_id = '1173612' my_league_key = nfl_game_key + '.l.' + my_league_id my_league_key = '314.l.1173612' resp, content = get_yahoo_api_data('league/' + my_league_key + '/metadata', session['yahoo_token'][0], session['yahoo_token'][1]) if resp.status == 401: return redirect( url_for('yahoo_oauth', next=url_for('yahoo_get_league') or None)) #YAHOO HELPER goes here to process content (processed json) yahoo_helper = YahooHelper() yahoo_helper.import_json_data(content, get="leagues") processed_data = yahoo_helper.return_data() # note: still need to get team number in league return render_template('yahoo.html', what_data='league', resp=resp, data=content, league_id=processed_data[0], start_date=processed_data[1], end_date=processed_data[2], league_url=processed_data[4], num_teams=processed_data[3], user_id=processed_data[6])
def get_stats(): """get weekly fantasy scores by team""" yahoo_helper = YahooHelper() yahoo_api_caller = YahooAPICaller() yahoo_db_helper = Db_Helper() if not 'yahoo_token' in session.keys(): return redirect(url_for('yahoo_oauth', next=url_for('get_stats') or None)) ### !!!!!!! league_key = 'nfl.l.1173612' ### there should be a call to the database for league key here. token_1, token_2 = session['yahoo_token'][0], session['yahoo_token'][1] #yahoo_api_caller.load_keys(token_1=token_1, token_2=token_2) params = {'week':'9' } ## for current week resp, content = get_yahoo_api_data('league/' + league_key + '/scoreboard', session['yahoo_token'][0], session['yahoo_token'][1], extras=params) if resp.status == 401: return redirect(url_for('yahoo_oauth', next=url_for('get_stats') or None)) yahoo_helper.import_json_data(content, get='team_stats') processed_data = yahoo_helper.return_data() #<== stats_dict returned here yahoo_db_helper.brians_import_team_stats(processed_data) #<== stats_dict being parsed # # SHOULD MAKE DB CALLS HERE TO PULL DATA NOW. # return render_template('yahoo.html', what_data = 'stats', resp = resp, processed_data = processed_data, content = content )
def yahoo_get_league(): '''get own fantasy team roster. need to add these extra fields into to postgresql database. goal: be able to query fantasy_league_id -> fantasy_team_id -> fantasy_players list''' if not 'yahoo_token' in session.keys(): return redirect(url_for('yahoo_oauth', next=url_for('yahoo_get_league') or None)) nfl_game_key = 'nfl' my_league_id = '1173612' my_league_key = nfl_game_key + '.l.' + my_league_id my_league_key = '314.l.1173612' resp, content = get_yahoo_api_data('league/' + my_league_key + '/metadata', session['yahoo_token'][0], session['yahoo_token'][1]) if resp.status == 401: return redirect(url_for('yahoo_oauth', next=url_for('yahoo_get_league') or None)) #YAHOO HELPER goes here to process content (processed json) yahoo_helper = YahooHelper() yahoo_helper.import_json_data(content, get="leagues") processed_data=yahoo_helper.return_data() # note: still need to get team number in league return render_template('yahoo.html', what_data = 'league', resp = resp, data=content, league_id = processed_data[0], start_date = processed_data[1], end_date = processed_data[2], league_url = processed_data[4], num_teams = processed_data[3], user_id=processed_data[6] )
def yahoo_get_players(): #get own fantasy team players within a league if not 'yahoo_token' in session.keys(): return redirect( url_for('yahoo_oauth', next=url_for('yahoo_get_players') or None)) game_key = 'nfl' league_id = '1173612' team_id = '8' team_key_format = game_key + '.l.' + league_id + '.t.' + team_id #my_league_key = nfl_game_key + '.l.' + my_league_id my_league_key = '314.l.1173612' league_key = 'nfl.l.1173612' team_key = '314.l.1173612.t.8' temp = dict() # THIS SHOULDNT BE HARD CODED param = {'week': '12'} resp, content = get_yahoo_api_data('team/' + team_key + '/roster/players', session['yahoo_token'][0], session['yahoo_token'][1], extras=param) if resp.status == 401: return redirect( url_for('yahoo_oauth', next=url_for('yahoo_get_players') or None)) # call yahoo api HELPER yahoo_api_helper = YahooHelper() yahoo_api_helper.import_json_data(content, get='players') yahoo_api_helper.return_data() # this gets team data from collection, may just only need one API call. #full_content = content['fantasy_content']['team'][0] #last ['14'] parameter represents the player #full_content = content['fantasy_content']['team'][1]['roster']['0']['players']['14'] full_content = content['fantasy_content']['team'][1]['roster']['0'][ 'players']['14'] player_data = content['fantasy_content']['team'][1]['roster']['0'][ 'players']['1'] temp = player_data['player'][0][15] #iteritems() -> #iterkeys() #itervalues() data_wanted = ["u'player_key"] #, "u'player_id"] isolated = list() temp_list = list() temp_list2 = list() temp_value = player_data['player'][0] for value in temp_value: temp_list.append(type(value)) #for value in itertools.islice(value,4,5): # isolated = value if type(value) == dict: for attr in data_wanted: if value.has_key(u'player_key'): isolated = value[u'player_key'] pass for key, value in value.iteritems(): temp_list2.append(key) #isolated.append(value) #else: # temp_list = 'isn\'t a dict' roster_position = player_data['player'][1]['selected_position'][1][ 'position'] yahoo_player_key = player_data['player'][0][0]['player_key'] yahoo_player_id = player_data['player'][0][1]['player_id'] yahoo_full_name = player_data['player'][0][2]['name']['full'] yahoo_first_name = player_data['player'][0][2]['name']['first'] yahoo_players_team = player_data['player'][0][5] #yahoo_last_name = player_data['player'][0][2]['name']['last'] yahoo_last_name = player_data['player'][0][2]['name'] #yahoo_players_bye_week = player_data['player'][0][7]['bye_weeks']['week'] yahoo_players_bye_week = player_data['player'][0][7] #yahoo_players_team_abbr = player_data['player'][0][6]['editorial_team_abbr'] yahoo_players_team_abbr = player_data['player'][0][6] #yahoo_players_number = player_data['player'][0][8]['uniform_number'] yahoo_players_number = player_data['player'][0][8] #yahoo_players_position = player_data['player'][0][9]['display_position'] yahoo_players_position = player_data['player'][0][9] #position = player_data['player'][1][] return render_template('yahoo.html', what_data='players', isolated=isolated, temp_list=temp_list, temp_list2=temp_list2, temp=temp, resp=resp, data=content, player_data=player_data, full_content=content, roster_position=roster_position, yahoo_player_key=yahoo_player_key, yahoo_player_id=yahoo_player_id, yahoo_full_name=yahoo_full_name, yahoo_first_name=yahoo_first_name, yahoo_last_name=yahoo_last_name, yahoo_players_team=yahoo_players_team, yahoo_players_team_abbr=yahoo_players_team_abbr, yahoo_player_bye_week=yahoo_players_bye_week, yahoo_players_number=yahoo_players_number, yahoo_players_position=yahoo_players_position)
def yahoo_get_players(): #get own fantasy team players within a league if not 'yahoo_token' in session.keys(): return redirect(url_for('yahoo_oauth', next=url_for('yahoo_get_players') or None)) game_key = 'nfl' league_id = '1173612' team_id = '8' team_key_format = game_key + '.l.' + league_id + '.t.' + team_id #my_league_key = nfl_game_key + '.l.' + my_league_id my_league_key = '314.l.1173612' league_key = 'nfl.l.1173612' team_key = '314.l.1173612.t.8' temp = dict() # THIS SHOULDNT BE HARD CODED param = {'week':'12'} resp, content = get_yahoo_api_data('team/' + team_key + '/roster/players', session['yahoo_token'][0], session['yahoo_token'][1], extras=param) if resp.status == 401: return redirect(url_for('yahoo_oauth', next=url_for('yahoo_get_players') or None)) # call yahoo api HELPER yahoo_api_helper=YahooHelper() yahoo_api_helper.import_json_data(content, get='players') yahoo_api_helper.return_data() # this gets team data from collection, may just only need one API call. #full_content = content['fantasy_content']['team'][0] #last ['14'] parameter represents the player #full_content = content['fantasy_content']['team'][1]['roster']['0']['players']['14'] full_content = content['fantasy_content']['team'][1]['roster']['0']['players']['14'] player_data = content['fantasy_content']['team'][1]['roster']['0']['players']['1'] temp = player_data['player'][0][15] #iteritems() -> #iterkeys() #itervalues() data_wanted = ["u'player_key"]#, "u'player_id"] isolated = list() temp_list = list() temp_list2 = list() temp_value = player_data['player'][0] for value in temp_value: temp_list.append(type(value)) #for value in itertools.islice(value,4,5): # isolated = value if type(value) == dict: for attr in data_wanted: if value.has_key(u'player_key'): isolated = value[u'player_key'] pass for key, value in value.iteritems(): temp_list2.append(key) #isolated.append(value) #else: # temp_list = 'isn\'t a dict' roster_position = player_data['player'][1]['selected_position'][1]['position'] yahoo_player_key = player_data['player'][0][0]['player_key'] yahoo_player_id = player_data['player'][0][1]['player_id'] yahoo_full_name = player_data['player'][0][2]['name']['full'] yahoo_first_name = player_data['player'][0][2]['name']['first'] yahoo_players_team = player_data['player'][0][5] #yahoo_last_name = player_data['player'][0][2]['name']['last'] yahoo_last_name = player_data['player'][0][2]['name'] #yahoo_players_bye_week = player_data['player'][0][7]['bye_weeks']['week'] yahoo_players_bye_week = player_data['player'][0][7] #yahoo_players_team_abbr = player_data['player'][0][6]['editorial_team_abbr'] yahoo_players_team_abbr = player_data['player'][0][6] #yahoo_players_number = player_data['player'][0][8]['uniform_number'] yahoo_players_number = player_data['player'][0][8] #yahoo_players_position = player_data['player'][0][9]['display_position'] yahoo_players_position = player_data['player'][0][9] #position = player_data['player'][1][] return render_template('yahoo.html', what_data = 'players', isolated = isolated, temp_list = temp_list, temp_list2 = temp_list2, temp = temp, resp = resp, data=content, player_data = player_data, full_content = content, roster_position = roster_position, yahoo_player_key = yahoo_player_key, yahoo_player_id = yahoo_player_id, yahoo_full_name = yahoo_full_name, yahoo_first_name = yahoo_first_name, yahoo_last_name = yahoo_last_name, yahoo_players_team = yahoo_players_team, yahoo_players_team_abbr = yahoo_players_team_abbr, yahoo_player_bye_week = yahoo_players_bye_week, yahoo_players_number = yahoo_players_number, yahoo_players_position = yahoo_players_position )