From 21880c47ba381221b9a269c0aa2e83b11d8eb945 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 20 Oct 2021 00:03:07 +0800 Subject: More work on web console --- jimbrella/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'jimbrella/utils.py') diff --git a/jimbrella/utils.py b/jimbrella/utils.py index a9f4623..09f0ae2 100644 --- a/jimbrella/utils.py +++ b/jimbrella/utils.py @@ -1,6 +1,20 @@ +from datetime import datetime, timedelta +from .config import * + + def group_by_status(umbrellas: list) -> dict: keys = set([umb["status"] for umb in umbrellas]) statuses = {} for key in keys: statuses[key] = [umb for umb in umbrellas if umb["status"] == key] return statuses + + +def find_overdue(umbrellas: list) -> list: + now = datetime.now() + return [ + umb + for umb in umbrellas + if umb["lent_at"] is not None + and now - umb["lent_at"] > timedelta(hours=DUE_HOURS) + ] -- cgit v1.2.3