#Chad Williamson import requests from discord.ext import commands import discord bot = commands.Bot(command_prefix="!") @bot.command(name="statReport", help="Generate weekly stat report") async def statReport(ctx, INPUTweekNum: int): weekNum = INPUTweekNum #parameter authC_ID = "removed->leagueID" authC_E = "removed->league" rF = [] x = requests.get("removed->leagueURL", params={"scoringPeriodId": weekNum}, cookies={"SWID": authC_ID, "espn_s2": authC_E}) y = x.json() t0 = []; t1 = []; t2 = []; t3 = []; t4 = []; t5 = []; t6 = []; t7 = []; t8 = []; t9 = []; t10 = []; t11 = []; t12 = []; t13 = [] LLL = [t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13] for item in y["teams"]: t = item["id"] for pL in item["roster"]["entries"]: n = pL["playerPoolEntry"]["player"]["fullName"] s = pL["lineupSlotId"] p, a = None, None for pS in pL["playerPoolEntry"]["player"]["stats"]: if pS["scoringPeriodId"] != weekNum: continue if pS["statSourceId"] == 0: a = pS["appliedTotal"] elif pS["statSourceId"] == 1: p = pS["appliedTotal"] rF.append([weekNum, t, n, s, p, a]) LLL[t].append([n, s, p, a]) #loop through every team. ensure 16 roster spots. add a 17th indice with summation values z = 1 underPerVal = 1000; underPerIndex = 0; overPerVal = 0; overPerIndex = 0; lowBenchVal = 1000; lowBenchIndex = 0; highBenchVal = 0; highBenchIndex = 0; highScoreVal = 0; highScoreInd = 0; lowScoreVal = 1000; lowScoreInd = 0 topQBVal = 0; topQBInd = 0; topRBVal = 0; topRBInd = 0; topWRVal = 0; topWRInd = 0; topBenchVal = 0; topBenchInd = 0; topTEVal = 0; topTEInd = 0; topFlexVal = 0; topFlexInd = 0; topDEFVal = 0; topDEFInd = 0; topKV = 0; topKInd = 0 qbN = ""; rbN = ""; wrN = ""; teN = ""; fxN = ""; defN = ""; kN = ""; benchN = "" while (z < 14): #var sActScore = 0; sProjScore = 0; sBenchScore = 0; deltaScore = 0; #ensure rosters have minimum of 16 entries buff = 16 - len(LLL[z]) if (buff): i = 0 while (i < buff): LLL[z].append(["nullName", 99, 0, 0]) i += 1 #take care of null values for row in LLL[z]: if(str(row[2]) == "None"): row[2] = 0 if(str(row[3]) == "None"): row[3] = 0 if (row[1] != 20 and row[1] != 21 and row[1] != 99): sActScore += row[3] sProjScore += row[2] if (row[1] == 0): if (row[3] > topQBVal): topQBVal = round(row[3],1) topQBInd = z qbN = row[0] if (row[1] == 2): if (row[3] > topRBVal): topRBVal = round(row[3],1) topRBInd = z rbN = row[0] if (row[1] == 4): if (row[3] > topWRVal): topWRVal = round(row[3],1) topWRInd = z wrN = row[0] if (row[1] == 6): if (row[3] > topTEVal): topTEVal = round(row[3],1) topTEInd = z teN = row[0] if (row[1] == 23): if (row[3] > topFlexVal): topFlexVal = round(row[3],1) topFlexInd = z fxN = row[0] if (row[1] == 16): if (row[3] > topDEFVal): topDEFVal = round(row[3],1) topDEFInd = z defN = row[0] if (row[1] == 17): if (row[3] > topKV): topKV = round(row[3],1) topKInd = z kN = row[0] if (row[1] == 20 or row[1] == 21): sBenchScore += row[3] if (row[3] > topBenchVal): topBenchVal = round(row[3],1) topBenchInd = z benchN = row[0] if (sProjScore == 0): sProjScore = 1; deltaScore = round(((sActScore / sProjScore) * 100),1) sActScore = round(sActScore, 1); sProjScore = round(sProjScore, 1); sBenchScore = round(sBenchScore, 1); LLL[z].append([sActScore, sProjScore, sBenchScore, deltaScore]) if (deltaScore > overPerVal): overPerVal = deltaScore overPerIndex = z if (deltaScore < underPerVal): underPerVal = deltaScore underPerIndex = z if (sBenchScore > highBenchVal): highBenchVal = sBenchScore highBenchIndex = z if (sBenchScore < lowBenchVal): lowBenchVal = sBenchScore lowBenchIndex = z if (sActScore > highScoreVal): highScoreVal = sActScore highScoreInd = z if (sActScore < lowScoreVal): lowScoreVal = sActScore lowScoreInd = z z += 1 bWVal = 0; bW_Win = 0; bW_Lin = 0; cWVal = 1000; cW_Win = 0; cW_Lin = 0; for matchup in y["schedule"]: if (matchup["matchupPeriodId"] == weekNum): if (matchup["winner"] != "UNDECIDED"): #print() if(((matchUpOutcome(LLL, matchup["home"]["teamId"], matchup["away"]["teamId"]))[2]) > bWVal): bWVal = ((matchUpOutcome(LLL, matchup["home"]["teamId"], matchup["away"]["teamId"]))[2]) bW_Win = ((matchUpOutcome(LLL, matchup["home"]["teamId"], matchup["away"]["teamId"]))[0]) bW_Lin = ((matchUpOutcome(LLL, matchup["home"]["teamId"], matchup["away"]["teamId"]))[1]) if(((matchUpOutcome(LLL, matchup["home"]["teamId"], matchup["away"]["teamId"]))[2]) < cWVal): cWVal = ((matchUpOutcome(LLL, matchup["home"]["teamId"], matchup["away"]["teamId"]))[2]) cW_Win = ((matchUpOutcome(LLL, matchup["home"]["teamId"], matchup["away"]["teamId"]))[0]) cW_Lin = ((matchUpOutcome(LLL, matchup["home"]["teamId"], matchup["away"]["teamId"]))[1]) emb = discord.Embed(title="Prestige Worldwide - Week " + str(INPUTweekNum), colour = discord.Colour.blue()) emb.add_field(name=" 💪 Over-performer 💪 ", value= overPerformer(overPerIndex, overPerVal), inline=False) emb.add_field(name=" 😴 Under-performer 😴 ", value= underPerformer(underPerIndex, underPerVal), inline=False) emb.add_field(name=" 🏆 Best Manager 🏆 ", value= lowestBench(lowBenchIndex, lowBenchVal), inline=False) emb.add_field(name=" 🚮 Worst Manager 🚮 ", value= highestBench(highBenchIndex, highBenchVal), inline=False) emb.add_field(name=" 😂 Biggest Win 😂 ", value= biggestWin(bWVal, bW_Win, bW_Lin), inline=False) emb.add_field(name=" 😨 Narrowest Win 😨 ", value= closestWin(cWVal, cW_Win, cW_Lin), inline=False) emb.add_field(name=" 👑 Highest Score 👑 ", value= highestScore(highScoreVal, highScoreInd), inline=False) emb.add_field(name=" 💀 Lowest Score 💀 ", value= lowestScore(lowScoreVal, lowScoreInd), inline=False) emb.add_field(name=" 🏈 Top QB 🏈 ", value= topQB(qbN, topQBVal, topQBInd), inline=False) emb.add_field(name=" 🏈 Top RB 🏈 ", value = topRB(rbN, topRBVal, topRBInd), inline=False) emb.add_field(name=" 🏈 Top WR 🏈 ", value= topWR(wrN, topWRVal, topWRInd), inline=False) emb.add_field(name=" 🏈 Top TE 🏈 ", value= topTE(teN, topTEVal, topTEInd), inline=False) emb.add_field(name=" 🏈 Top Flex 🏈 ", value= topFLEX(fxN, topFlexVal, topFlexInd), inline=False) emb.add_field(name=" 🏈 Top Defense 🏈 ", value= topDEF(defN, topDEFVal, topDEFInd), inline=False) emb.add_field(name=" 🏈 Top Kicker 🏈 ", value= topK(kN, topKV, topKInd), inline=False) emb.add_field(name=" 💩 Benchwarmer 💩 ", value= topBench(benchN, topBenchVal, topBenchInd), inline=False) await ctx.send("", embed=emb) #output def topQB(tQBN, tQBV, tQBI): return(tQBN + " scored " + str(tQBV) + " points for " + nameEnum(tQBI)) def topRB(tRBN, tRBV, tRBI): return(tRBN + " scored " + str(tRBV) + " points for " + nameEnum(tRBI)) def topWR(tWRN, tWRV, tWRI): return(tWRN + " scored " + str(tWRV) + " points for " + nameEnum(tWRI)) def topTE(tTEN, tTEV, tTEI): return(tTEN + " scored " + str(tTEV) + " points for " + nameEnum(tTEI)) def topFLEX(tFLEXN, tFLEXV, tFLEXI): return(tFLEXN + " scored " + str(tFLEXV) + " points for " + nameEnum(tFLEXI)) def topDEF(tdN, tdV, tdI): return(tdN + " scored " + str(tdV) + " points for " + nameEnum(tdI)) def topK(tkN, tkV, tkI): return(tkN + " scored " + str(tkV) + " points for " + nameEnum(tkI)) def topBench(tbN, tbV, tbI): return(nameEnum(tbI) + " wasted " + tbN + ""s " + str(tbV) + " points") def lowestScore(lowVal, lowIndex): return(nameEnum(lowIndex) + " only scored " + str(lowVal) + " points") def highestScore(highVal, highIndex): return(nameEnum(highIndex) + " scored " + str(highVal) + " points") def biggestWin(bValF, bValW, bValL): return(nameEnum(bValW) + " beat " + nameEnum(bValL) + " by " + str(bValF) + " points") def closestWin(cValF, cValW, cValL): return(nameEnum(cValW) + " beat " + nameEnum(cValL) + " by " + str(cValF) + " points") def overPerformer(ovI, ovV): return(nameEnum(ovI) + " scored " + str(ovV) + "% of his projected score") def underPerformer(unI, unV): return(nameEnum(unI) + " scored " + str(unV) + "% of his projected score") def lowestBench(lbI, lbV): return(nameEnum(lbI) + " left only " + str(lbV) + " points on his bench") def highestBench(hbI, hbV): return(nameEnum(hbI) + " left " + str(hbV) + " points on his bench") def matchUpOutcome(mdA, teamA, teamB): #output a tuple consisting of: winner, loser, difference if (mdA[teamA][16][0] >= mdA[teamB][16][0]): return(teamA, teamB, round(mdA[teamA][16][0] - mdA[teamB][16][0],1)) elif (mdA[teamA][16][0] < mdA[teamB][16][0]): return(teamB, teamA, round(mdA[teamB][16][0] - mdA[teamA][16][0],1)) def nameEnum(x): if (int(x) == 1): return("LeagueMemberName1") elif(int(x) == 2): return("LeagueMemberName2") elif(int(x) == 3): return("LeagueMemberName3") elif(int(x) == 4): return("LeagueMemberName4") elif(int(x) == 5): return("LeagueMemberName5") elif(int(x) == 6): return("LeagueMemberName6") elif(int(x) == 7): return("LeagueMemberName7") elif(int(x) == 8): return("LeagueMemberName8") elif(int(x) == 9): return("LeagueMemberName9") elif(int(x) == 10): return("LeagueMemberName10") elif(int(x) == 11): return("LeagueMemberName11") elif(int(x) == 12): return("LeagueMemberName12") elif(int(x) == 13): return("LeagueMemberName13") bot.run("removed->discordserver")