예제 #1
0
def main():
    dot = League(dot_id, year)
    bob = League(bob_id, year)
    dot_scoreboard = dot.scoreboard()
    bob_scoreboard = bob.scoreboard()

    return render_template('matchups.html', bob = bob, dot = dot, bob_scoreboard = bob_scoreboard, dot_scoreboard = dot_scoreboard)
예제 #2
0
def get_matchup():
    dot = League(dot_id, year)
    bob = League(bob_id, year)
    dot_score = dot.scoreboard()
    bob_score = bob.scoreboard()
    
    leagues = {
        bob: bob,
        dot: dot
    }
    data = {
        'dot_matchup': dot_score,
        'bob_matchup': bob_score
    }
    return jsonpickle.encode(data)
예제 #3
0
def get_scoreboard_df(league_id, year, week):
    league = League(league_id, year)
    scoreboard = league.scoreboard(week=week)
    scoreboard_list_of_dicts = [{
        'Home_Team':
        matchup.home_team.team_name.title(),
        'Home_Owner':
        clean_owner(matchup.home_team.owner.title()),
        'Home_Score':
        matchup.home_score,
        'Home_Wins':
        matchup.home_team.wins,
        'Home_Losses':
        matchup.home_team.losses,
        'Away_Team':
        matchup.away_team.team_name.title(),
        'Away_Owner':
        clean_owner(matchup.away_team.owner.title()),
        'Away_Score':
        matchup.away_score,
        'Away_Wins':
        matchup.away_team.wins,
        'Away_Losses':
        matchup.away_team.losses,
        'Winner':
        matchup.home_team.team_name.title()
        if matchup.home_score > matchup.away_score else
        matchup.away_team.team_name.title(),
        'Loser':
        matchup.home_team.team_name.title()
        if matchup.home_score < matchup.away_score else
        matchup.away_team.team_name.title()
    } for matchup in scoreboard]

    cols = ['Team', 'Owner', 'Score', 'Wins', 'Losses']
    # Updating Wins and Losses based on this week's result
    for matchup_dict in scoreboard_list_of_dicts:
        if matchup_dict['Winner'] == matchup_dict['Home_Team']:
            matchup_dict['Home_Wins'] += 1
            matchup_dict['Away_Losses'] += 1
            for col in cols:
                matchup_dict['Winning_' + col] = str(matchup_dict['Home_' +
                                                                  col])
                matchup_dict['Losing_' + col] = str(matchup_dict['Away_' +
                                                                 col])
        else:
            matchup_dict['Away_Wins'] += 1
            matchup_dict['Home_Losses'] += 1
            for col in cols:
                matchup_dict['Winning_' + col] = str(matchup_dict['Away_' +
                                                                  col])
                matchup_dict['Losing_' + col] = str(matchup_dict['Home_' +
                                                                 col])

    scoreboard_df = pd.DataFrame(scoreboard_list_of_dicts)
    scoreboard_df = scoreboard_df[['Winning_' + col for col in cols] +
                                  ['Losing_' + col for col in cols]]
    return scoreboard_df
예제 #4
0
def get_scoreboard(league_id, year):
    '''Gets current week's scoreboard'''
    league = League(league_id, year)
    matchups = league.scoreboard()
    score = [
        '%s\t %s - %s\t %s' % (i.home_team.team_abbrev, i.home_score,
                               i.away_score, i.away_team.team_abbrev)
        for i in matchups if i.away_team
    ]
    text = ['Score Update'] + score
    return '\n'.join(text)
예제 #5
0
파일: espn.py 프로젝트: blattus/lombardi
def initial_setup():
    # read in private league settings from config.py
    league_id = config.league_id
    year = config.year

    # credentials to let us see a private league
    espn_s2 = config.espn_s2
    swid = config.swid

    # get league info from ESPN
    league = League(league_id,year,espn_s2,swid)

    # define some variables for convenience
    global scoreboard
    global teams
    global settings
    global power_rankings

    scoreboard = league.scoreboard()
    teams = league.teams
    settings = league.settings
    power_rankings = league.power_rankings
예제 #6
0
파일: espn.py 프로젝트: trenigma/lombardi
def initial_setup():
    # read in private league settings from config.py
    league_id = config.league_id
    year = config.year

    # credentials to let us see a private league
    espn_s2 = config.espn_s2
    swid = config.swid

    # get league info from ESPN
    league = League(league_id, year, espn_s2, swid)

    # define some variables for convenience
    global scoreboard
    global teams
    global settings
    global power_rankings

    scoreboard = league.scoreboard()
    teams = league.teams
    settings = league.settings
    power_rankings = league.power_rankings
예제 #7
0
        return self.totalScore


# END SERIALIZABLE CLASSES

# get my team's overall data and write to disk
league = League(league_id, year)
teams = league.teams
my_team = next(team for team in teams if team.team_id == my_team_id)
team_obj = TeamObj(my_team.team_name, my_team.scores, my_team.wins,
                   my_team.losses)
team_obj.gettotal(team_obj.all_scores)
with open('team.json', 'w') as f:
    json.dump(team_obj.__dict__, f)

# get my week's data and write to disk
week = league.scoreboard(week=this_week)
week_match = getmatch(week, my_team_id)
# print(type(week_match))
# for vars in week_match:
# print(type(vars))
# for key, value in week_match.items():
# print (key, type(value), value)
with open('week.json', 'w') as f:
    json.dump(week_match, f)
# print(week_match.items())
# pprint(week_match)
# print(vars(week_match))
# match_team = getteams(week_match)
# pprint(my_match)
예제 #8
0
	output.writelines(header)

	for team in teams:
		s = team.team_name + " (" + team.owner + ")"
		row = s + "," + str(team.wins) + "," + str(team.losses) + "," + str(team.ties) + "," + str(team.points_for) + "," + str(team.points_against) + "\n"
		output.writelines(row)


	if year == 2017:
		# Output information to file
		file_name = str(year) + "matchups.csv"
		output = open(file_name, 'w')

		last_week = settings.final_season_count
		header = "Week,Match ID,Home Team,Home Team Score, ,Away Team Score,Away Team\n"
		output.writelines(header)


		for week in range(last_week):
			time = week + 1
			scoreboard = league.scoreboard(week=time)

			for i in range(matchup_count):

				matchup = scoreboard[i]
				row = str(time) + "," + str(i) +"," + matchup.home_team.team_name + "," + str(matchup.home_score) + ", v ," + str(matchup.away_score) + "," + matchup.away_team.team_name + "\n"
				output.writelines(row)

			output.writelines("\n")

output.close()
예제 #9
0
for team in current_teams:
    team.seasons = [{
        "year": 2018,
        "wins": team.wins,
        "losses": team.losses,
        "points_for": team.points_for,
        "points_against": team.points_against
    }]

# get all time records for each team
for year in range(2017, 2009, -1):

    league = League(league_id, year)

    #find champion for this year
    final_game = league.scoreboard()[0]
    if (final_game.home_score > final_game.away_score):
        champions.append({
            "year": year,
            "team_id": final_game.home_team.team_id
        })
    else:
        champions.append({
            "year": year,
            "team_id": final_game.away_team.team_id
        })

    for team in league.teams:
        current_team = next(
            (x for x in current_teams if x.team_id == team.team_id), None)
        if (current_team):
예제 #10
0
파일: stats.py 프로젝트: thedahc/FF-Bot-1
class Stats():
    def __init__(self, bot, league_id, year):
        self.bot = bot
        self.league_id = 273350
        self.year = 2017
        self.league = League(league_id, year)

    'Pulled the server channel ID to be stored in the database'
    async def on_server_join(self, server):
        print("test")
        print("Joining server: {0.id} ({0.name})".format(server))

    'League Info'
    @commands.has_permissions(administrator=True)
    @commands.command(pass_context=True)
    async def leagueid(self, ctx, *, id: str):
        try:
            try:
                self.league = League(int(id), 2017)
            except:
                await bot.say("Unable to find a league with ID \"" + id +"\".")
            print("New League ID: " + str(self.league.league_id))
            await self.bot.say("The league has been changed to: " + self.league.settings.name)
        except discord.errors.Forbidden:
            await self.bot.say("Missing Permissions.") 


    'Team Data Commands'
    @commands.command()
    async def teams(self):
        teamList = []
        await self.bot.say("Teams:\n==================")
        for team in self.league.teams:
            teamList.append(team.team_name)
        await self.bot.say('\n '.join(teamList))


    @commands.command()
    async def east(self):
        eastList = []
        await self.bot.say("East Division:\n==================")
        for team in self.league.teams:
            if team.division_id == 0:
                eastList.append(team.team_name)
                #await self.bot.say(team.team_name)
        await self.bot.say('\n'.join(eastList))

    @commands.command()
    # @commands.has_permissions(manage_messages=True)
    async def west(self):
        westList = []
        await self.bot.say("West Division:\n==================")
        for team in self.league.teams:
            if team.division_id == 1:
                westList.append(team.team_name)
                #await self.bot.say(team.team_name)
        await self.bot.say('\n'.join(westList))

    @commands.command(pass_context=True)
    async def won(self, ctx, *, name: str):
        for team in self.league.teams:
            if team.team_name.lower() == name.lower():
                await self.bot.say(team.team_name + " has won " + str(team.wins) + " games!")
                return
            elif name.lower() in team.owner.lower():
                await self.bot.say(team.owner + "'s team has won " + str(team.wins) + " games!")
                return
        await self.bot.say("Hmm...I couldn't find a team or owner named \"" + name + "\".")

    @commands.command(pass_context=True)
    async def lost(self, ctx, *, name: str):
        for team in self.league.teams:
            if team.team_name.lower() == name.lower():
                await self.bot.say(team.team_name + " has lost " + str(team.losses) + " games!")
                return
            elif name.lower() in team.owner.lower():
                await self.bot.say(team.owner + "'s team has lost " + str(team.losses) + " games!")
                return
        await self.bot.say("Hmm...I couldn't find a team or owner named \"" + name + "\".")

    @commands.command(pass_context=True)
    async def schedule(self, ctx, *, name: str):
        for team in self.league.teams:
            if team.team_name.lower() == name.lower():
                await self.bot.say(team.owner + "'s Schedule")
                await self.bot.say("==========================")
                await self.bot.say('\n'.join('Week {}:\t{}'.format(*k) for k in enumerate(ctx.message.author.roles, 1)))
                return
            elif name.lower() in team.owner.lower():
                await self.bot.say(team.owner + "'s Schedule")
                await self.bot.say("==========================")
                await self.bot.say('\n'.join('Week {}:\t{}'.format(*k) for k in enumerate(map(attrgetter('owner'), team.schedule), 1)))
                return
        await self.bot.say("Hmm...I couldn't find a team or owner named \"" + name + "\".")

    @commands.command(pass_context=True)
    async def points_for(self, ctx, *, name: str):
        for team in self.league.teams:
            if team.team_name.lower() == name.lower():
                await self.bot.say(team.owner + " has scored " + str(team.points_for) + " total points")
                return
            elif name.lower() in team.owner.lower():
                await self.bot.say(team.owner + " has scored " + str(team.points_for) + " total points")
                return
        await self.bot.say("Hmm...I couldn't find a team or owner named \"" + name + "\".")

    @commands.command(pass_context=True)
    async def points_against(self, ctx, *, name: str):
        for team in self.league.teams:
            if team.team_name.lower() == name.lower():
                await self.bot.say(team.owner + " has had " + str(team.points_for) + " total points scored against them.")
                return
            elif name.lower() in team.owner.lower():
                await self.bot.say(team.owner + " has had " + str(team.points_for) + " total points scored against them.")
                return
        await self.bot.say("Hmm...I couldn't find a team or owner named \"" + name + "\".")

    @commands.command(pass_context=True)
    async def scores(self, ctx, *, name: str):
        for team in self.league.teams:
            if team.team_name.lower() == name.lower():
                await self.bot.say(team.owner + "'s Scores\n==========================")
                await self.bot.say('\n'.join('Week {}:\t{}'.format(*k) for k in enumerate(team.scores, 1)))
                return
            elif name.lower() in team.owner.lower():
                await self.bot.say(team.owner + "'s Scores\n==========================")
                await self.bot.say('\n'.join('Week {}:\t{}'.format(*k) for k in enumerate(team.scores, 1)))
                return
        await self.bot.say("Hmm...I couldn't find a team or owner named \"" + name + "\".")

    @commands.command(pass_context=True)
    async def ranking(self, ctx, *, week_num):
        'Need to fix the ranking output'
        await self.bot.say('\n'.join('{}:\t{}'.format(*k) for k in enumerate(league.power_rankings(week=int(week_num)), 1)))

    @commands.command()
    async def scoreboard(self):
        scoreboard = self.league.scoreboard()
        counter = 0
        await self.bot.say("Current Week Matchups\n==========================")
        for score in scoreboard:
            matchup = scoreboard[counter]
            await self.bot.say(matchup.home_team.owner + ":\t" + str(matchup.home_score) + " pts\tvs.\t" + matchup.away_team.owner + ":\t" + str(matchup.away_score) + "pts ")
            counter = counter + 1

    @commands.command(pass_context=True)
    async def ping(self, ctx):
        pingtime = time.time()
        pingms = await self.bot.say("Pinging... `{}'s` location".format(ctx.message.author.mention))
        ping = time.time() - pingtime
        await self.bot.edit_message(pingms, "The ping time is `%.01f seconds`" % ping)