Skip to content

Commit

Permalink
Fixing issue with stats in NHL leagues
Browse files Browse the repository at this point in the history
  • Loading branch information
DMcP89 committed Oct 18, 2024
1 parent 979bf35 commit 4ddba64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
20 changes: 11 additions & 9 deletions harambot/cogs/yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ async def trade(self, interaction: discord.Interaction):
player_set0.append(player["name"])
api_details = (
self.get_player_text(
self.yahoo_api.get_player_details(player["name"], guild_id=interaction.guild_id)
self.yahoo_api.get_player_details(
player["name"], guild_id=interaction.guild_id
)
)
+ "\n"
)
Expand All @@ -155,7 +157,9 @@ async def trade(self, interaction: discord.Interaction):
player_set1_details = ""
for player in latest_trade["tradee_players"]:
player_set1.append(player["name"])
player_details = self.yahoo_api.get_player_details(player["name"], guild_id=interaction.guild_id)
player_details = self.yahoo_api.get_player_details(
player["name"], guild_id=interaction.guild_id
)
if player_details is None:
await interaction.followup.send(self.error_message)
return
Expand Down Expand Up @@ -267,13 +271,11 @@ def get_player_embed(self, player):
value=player["stats"]["total_points"],
inline=False,
)
del player["stats"]["player_id"]
del player["stats"]["name"]
del player["stats"]["position_type"]
for key, value in player["stats"].items():
if key == "total_points":
continue
embed.add_field(name=key, value=value)
if len(player["stats"].items()) < 20:
for key, value in player["stats"].items():
if key == "total_points":
continue
embed.add_field(name=key, value=value)
return embed

def get_player_text(self, player):
Expand Down
12 changes: 7 additions & 5 deletions harambot/yahoo_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,17 @@ def get_player_details(self, player_name, guild_id, week=None):
req_type="week",
week=week,
)[0]
if len(stats) > 25:
player["stats"] = stats[:20]
else:
player["stats"] = stats
else:
player["stats"] = self.league().player_stats(
stats = self.league().player_stats(
[player["player_id"]],
req_type="season",
)[0]
del stats["player_id"]
del stats["name"]
del stats["position_type"]
if len(stats) > 20:
stats = {k: v for k, v in stats.items() if v != 0.0}
player["stats"] = stats
return player
except Exception:
logger.exception(
Expand Down

0 comments on commit 4ddba64

Please sign in to comment.