From a3ca61f1c7c3147fbdef4f07573bf23e13680167 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Tue, 11 Jan 2022 20:20:54 +0100 Subject: [PATCH] Inventory fetch now sorts campaigns --- twitch.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/twitch.py b/twitch.py index 2da336e..279b416 100644 --- a/twitch.py +++ b/twitch.py @@ -687,14 +687,12 @@ class Twitch: async def fetch_inventory(self) -> None: response = await self.gql_request(GQL_OPERATIONS["Inventory"]) - inventory = response["data"]["currentUser"]["inventory"] - if inventory["dropCampaignsInProgress"]: # None with no available campaigns - self.inventory = [ - DropsCampaign(self, data) for data in inventory["dropCampaignsInProgress"] - ] - else: - # can happen if the user has no active campaigns yet - self.inventory = [] + inventory = response["data"]["currentUser"]["inventory"]["dropCampaignsInProgress"] or [] + campaigns = sorted( + (DropsCampaign(self, data) for data in inventory), + key=lambda c: c.ends_at, + ) + self.inventory = campaigns def get_drop(self, drop_id: str) -> Optional[TimedDrop]: for campaign in self.inventory: