Skip to content

Commit

Permalink
Fixed ESPN League Loader
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyagreco committed Dec 6, 2023
1 parent c06aedf commit e2c30c2
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 54 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file.

- N/A

## [2.6.1]

- Updated logic in ESPN League Loader to work with new ESPN owner flow

## [2.6.0]

- Fixed bug where older Sleeper leagues would sometimes fail to load
Expand Down Expand Up @@ -243,7 +247,8 @@ All notable changes to this project will be documented in this file.

### Initial Release

[Unreleased]: https://github.com/joeyagreco/leeger/compare/v2.6.0...HEAD
[Unreleased]: https://github.com/joeyagreco/leeger/compare/v2.6.1...HEAD
[2.6.1]: https://github.com/joeyagreco/leeger/releases/tag/v2.6.1
[2.6.0]: https://github.com/joeyagreco/leeger/releases/tag/v2.6.0
[2.5.5]: https://github.com/joeyagreco/leeger/releases/tag/v2.5.5
[2.5.4]: https://github.com/joeyagreco/leeger/releases/tag/v2.5.4
Expand Down
23 changes: 20 additions & 3 deletions leeger/league_loader/ESPNLeagueLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ def __loadOwners(self, espnTeams: list[ESPNTeam]) -> None:
owners = list()
for espnTeam in espnTeams:
# get general owner name if there is one
generalOwnerName = self._getGeneralOwnerNameFromGivenOwnerName(espnTeam.owner)
ownerName = generalOwnerName if generalOwnerName is not None else espnTeam.owner
ownerName = self.__getESPNOwnerName(espnTeam.owners)
generalOwnerName = self._getGeneralOwnerNameFromGivenOwnerName(ownerName)
ownerName = generalOwnerName if generalOwnerName is not None else ownerName
owners.append(Owner(name=ownerName))
self._owners = owners

Expand Down Expand Up @@ -227,8 +228,24 @@ def __buildTeams(self, espnTeams: list[ESPNTeam]) -> list[Team]:
for espnTeam in espnTeams:
# TODO: see if there are cases where ESPN leagues do NOT have divisions
divisionId = self.__espnDivisionIdToDivisionMap[espnTeam.division_id].id
owner = self._getOwnerByName(espnTeam.owner)
ownerName = self.__getESPNOwnerName(espnTeam.owners)
owner = self._getOwnerByName(ownerName)
team = Team(ownerId=owner.id, name=espnTeam.team_name, divisionId=divisionId)
teams.append(team)
self.__espnTeamIdToTeamMap[espnTeam.team_id] = team
return teams

def __getESPNOwnerName(self, espnOwners: list[dict]) -> str:
"""
Owners look like this:
[
{
"displayName": "FooBarBazQuz",
"firstName": "Foo",
"id": "{1B3463F3-B3C6-4053-9893-EdB9C7805888}",
"lastName": "Bar",
...
}
]
"""
return f"{espnOwners[0]['firstName']} {espnOwners[0]['lastName']}"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
espn_api~=0.33.0
espn_api~=0.34.0
fleaflicker~=1.0.0
numpy~=1.24.4
openpyxl~=3.1.2
Expand Down
Loading

0 comments on commit e2c30c2

Please sign in to comment.