From 38e7b7c405eb90d5593b65530caa5b61152aa63e Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 9 Sep 2019 22:29:10 +0100 Subject: [PATCH] Sort pins in stampbook by release date --- houdini/handlers/play/item.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/houdini/handlers/play/item.py b/houdini/handlers/play/item.py index 9c1de19..4a77f78 100644 --- a/houdini/handlers/play/item.py +++ b/houdini/handlers/play/item.py @@ -4,6 +4,7 @@ from houdini.data.item import Item, ItemCrumbsCollection import time from aiocache import cached +import operator def get_pin_string_key(_, p, player_id): @@ -22,12 +23,13 @@ async def get_pin_string(p, player_id): inventory = await ItemCrumbsCollection.get_collection(player_id) def get_string(pin): - pin = p.server.items[pin] - release_unix = int(time.mktime(pin.release_date.timetuple())) - return '|'.join(map(str, [pin.id, release_unix, int(pin.member)])) + unix = int(time.mktime(pin.release_date.timetuple())) + return f'{pin.id}|{unix}|{int(pin.member)}' - pins = [get_string(pin) for pin in inventory.keys() if p.server.items[pin].is_flag()] - return '%'.join(pins) + pins = sorted((p.server.items[pin] for pin in inventory.keys() + if (p.server.items[pin].is_flag() and p.server.items[pin].cost == 0)), + key=operator.attrgetter('release_date')) + return '%'.join(get_string(pin) for pin in pins) @cached(alias='default', key_builder=get_awards_string_key)