From 7cbd5c87afbdf93c006876bfcce58d73c79d8359 Mon Sep 17 00:00:00 2001 From: Dakota Date: Thu, 2 May 2024 11:58:20 +0200 Subject: [PATCH] feat: best inventory --- pyZUnivers/__init__.py | 3 ++- pyZUnivers/user.py | 8 ++++++-- pyZUnivers/utils.py | 9 +++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pyZUnivers/__init__.py b/pyZUnivers/__init__.py index 30b79e9..47b5748 100644 --- a/pyZUnivers/__init__.py +++ b/pyZUnivers/__init__.py @@ -12,5 +12,6 @@ DISCORD_DATE_FORMAT, is_advent_calendar, get_ascension_leaderboard, - get_inventory + get_inventory, + best_inventory ) \ No newline at end of file diff --git a/pyZUnivers/user.py b/pyZUnivers/user.py index 10ea979..e95af0a 100644 --- a/pyZUnivers/user.py +++ b/pyZUnivers/user.py @@ -22,7 +22,8 @@ Checker, ADVENT_INDEX, get_inventory, - parse_username + parse_username, + best_inventory ) class User: @@ -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) \ No newline at end of file + return get_inventory(self.__parsed_name, search) + + def best_inventory(self, limit: int = 10) -> List[UserInventoryObject]: + return best_inventory(self.__parsed_name, limit=limit) \ No newline at end of file diff --git a/pyZUnivers/utils.py b/pyZUnivers/utils.py index b84dcc3..80e0e86 100644 --- a/pyZUnivers/utils.py +++ b/pyZUnivers/utils.py @@ -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] \ No newline at end of file