Skip to content

Commit

Permalink
feat: best inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
MalikAza committed May 2, 2024
1 parent b97cb90 commit 7cbd5c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pyZUnivers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
DISCORD_DATE_FORMAT,
is_advent_calendar,
get_ascension_leaderboard,
get_inventory
get_inventory,
best_inventory
)
8 changes: 6 additions & 2 deletions pyZUnivers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
Checker,
ADVENT_INDEX,
get_inventory,
parse_username
parse_username,
best_inventory
)

class User:
Expand Down Expand Up @@ -329,4 +330,7 @@ def subscription_bonus(self) -> str:
return f"{self.__base_infos['subscriptionBonusCount']}/{self.__base_infos['subscriptionBonusLimit']}"

def get_inventory(self, search: str = None) -> List[UserInventoryObject]:
return get_inventory(self.__parsed_name, search)
return get_inventory(self.__parsed_name, search)

def best_inventory(self, limit: int = 10) -> List[UserInventoryObject]:
return best_inventory(self.__parsed_name, limit=limit)
9 changes: 7 additions & 2 deletions pyZUnivers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ def get_inventory(username: str, search: str = None): # TODO: Add filters

return result

def best_inventory(username: str, limit: int = 10):
def best_inventory(username: str, limit: int = 10) -> List[UserInventoryObject]:
inventory = get_inventory(username)
inventory = sorted(inventory, key=lambda x: x["quantity"], reverse=True)

def sorted_callback(x: UserInventoryObject) -> int:
if x["isGolden"]: return x["item"]["scoreGolden"]
return x["item"]["score"]

inventory = sorted(inventory, key=sorted_callback, reverse=True)

return inventory[:limit]

0 comments on commit 7cbd5c8

Please sign in to comment.