def __init__(self): self.teamData = {} self.pointsScored = {} self.oauth = OAuth1(None, None, from_file='./rankings/credentials.json') self.yql = myql.MYQL(format='json', oauth=self.oauth) self.current_week = 0
currentTime = time.time() formattedTime = time.strftime("%Z - %Y/%m/%d, %H:%M:%S", time.localtime(currentTime)) # TODO: this needs to be updated with your actual webhook #slackUrl = 'put-your-slack-webhook-url-here' oauth = OAuth1( None, None, from_file= '/home/ec2-user/yahoo-fantasy-football-slack-app/resources/credentials.json' ) if not oauth.token_is_valid(): oauth.refresh_access_token() yql = myql.MYQL(format='json', oauth=oauth) resp = yql.raw_query( 'select * from fantasysports.leagues.transactions where league_key="nfl.l.28709"' ) json_response = json.loads(resp.content.decode(resp.encoding)) transactions = json_response['query']['results']['league']['transactions'][ 'transaction'] with open( '/home/ec2-user/yahoo-fantasy-football-slack-app/resources/old-transactions.json', 'r') as thefile: oldTransactions = json.load(thefile) with open( '/home/ec2-user/yahoo-fantasy-football-slack-app/resources/old-transactions.json', 'w') as thefile: json.dump(transactions, thefile)
return "SW" if angle >= (6 * degree) and angle < (7 * degree): return "W" if angle >= (7 * degree) and angle < (8 * degree): return "NW" return "N" #Code of my city CODE = "2972" #Change to false if you want Fahrenheit and mph METRIC = True from myql.utils import pretty_json, pretty_xml yql = myql.MYQL(format='xml', community=True) #can't trust windchill if specified in celsius (must parse from fahrenheit) weather_xml = yql.raw_query('select * from weather.forecast where woeid = ' + CODE + ' and u ="f"') dom = minidom.parseString(weather_xml.content) xml_wind = dom.getElementsByTagName('yweather:wind') wind = xml_wind[0] chill = wind.getAttribute('chill') if METRIC: weather_xml = yql.raw_query( 'select * from weather.forecast where woeid = ' + CODE + ' and u ="c"') chill = str(int(round((float(chill) - 32) / 1.8))) dom = minidom.parseString(weather_xml.content)
def test_oauth1(): oauth = OAuth1(None, None, from_file='oauth1.json') yql = myql.MYQL(oauth=oauth) response = yql.get_guid('josue_brunel') logging.debug(pretty_json(response.content)) assert response.status_code == 200
def pull_data(playoff_length): # Authenticate oauth = OAuth1(None, None, from_file='creds.json') yql = myql.MYQL(format='json', oauth=oauth) if not oauth.token_is_valid(): oauth.refresh_access_token() # Pull league standings data and send to the json parser resp = yql.raw_query( 'select * from fantasysports.leagues.standings where league_key="nfl.l.553162"' ) league_standings = json.loads(resp.content) # Grab week data from json current_week = int( league_standings["query"]["results"]["league"]["current_week"]) end_week = int(league_standings["query"]["results"]["league"] ["end_week"]) - (playoff_length) remaining_weeks = end_week - current_week + 1 # Pull league schedules from remaining weeks from server and send to json parser schedules = [] for i in range(current_week, end_week + 1): resp = yql.raw_query( "select * from fantasysports.leagues.scoreboard where league_key='nfl.l.553162' and week='" + str(i) + "'") schedules.append(json.loads(resp.content)) #---------------------------- # Load all team data #---------------------------- teams = [] number_of_teams = int( league_standings["query"]["results"]["league"]["num_teams"]) # Add owners and fill array indices with dicts for i in range(0, number_of_teams): teams.append({ "name": str(league_standings["query"]["results"]["league"]["standings"] ["teams"]["team"][i]["name"]) }) # Fill in rest of data # Oh god I know this is ugly and ungraceful, please forgive me future me when you go to fix this for i in range(0, number_of_teams): # Add names of remaining opponents rem_sched = [] for j in range(0, len(schedules)): matchup_iterator = 0 matchup_pos = -1 while matchup_iterator <= 6: if schedules[j]["query"]["results"]["league"]["scoreboard"][ "matchups"]["matchup"][matchup_iterator]["teams"][ "team"][0]["name"] == teams[i]["name"]: matchup_pos = 1 break elif schedules[j]["query"]["results"]["league"]["scoreboard"][ "matchups"]["matchup"][matchup_iterator]["teams"][ "team"][1]["name"] == teams[i]["name"]: matchup_pos = 0 break else: matchup_iterator += 1 rem_sched.append( schedules[j]["query"]["results"]["league"]["scoreboard"] ["matchups"]["matchup"][matchup_iterator]["teams"]["team"] [matchup_pos]["name"]) # Format ppg (points per game) as a two point float try: ppg = float( league_standings["query"]["results"]["league"]["standings"] ["teams"]["team"][i]["team_points"]["total"]) ppg /= current_week - 1 ppg = float("{0:.2f}".format(ppg)) except ZeroDivisionError: ppg = 0 # Add the rest of data teams[i].update({ "icon": league_standings["query"]["results"]["league"]["standings"] ["teams"]["team"][i]["team_logos"]["team_logo"]["url"] }) teams[i].update({ "points": float(league_standings["query"]["results"]["league"]["standings"] ["teams"]["team"][i]["team_points"]["total"]) }) teams[i].update({ "wins": int(league_standings["query"]["results"]["league"]["standings"] ["teams"]["team"][i]["team_standings"]["outcome_totals"] ["wins"]) }) teams[i].update({ "losses": int(league_standings["query"]["results"]["league"]["standings"] ["teams"]["team"][i]["team_standings"]["outcome_totals"] ["losses"]) }) teams[i].update({ "ties": int(league_standings["query"]["results"]["league"]["standings"] ["teams"]["team"][i]["team_standings"]["outcome_totals"] ["ties"]) }) teams[i].update({"ppg": ppg}) teams[i].update({"rem_sched": rem_sched}) return teams