From df5870502abf79db2215af2ca747503738f20997 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 23 Jul 2022 00:13:40 -0700 Subject: [PATCH] Add syntax for now+seconds, now-seconds when parsing units. This helps a lot when it comes to querying for atom feeds. You can request the last X hours of items instead of picking some limit that you hope is high enough for the highs and wastes data during the lows. You want created=now-86400..now for one day. --- etiquette/helpers.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/etiquette/helpers.py b/etiquette/helpers.py index fd951ca..5795c05 100644 --- a/etiquette/helpers.py +++ b/etiquette/helpers.py @@ -347,14 +347,21 @@ def parse_unit_string(s) -> typing.Union[int, float, None]: if ':' in s: return hms.hms_to_seconds(s) - elif all(c in '0123456789' for c in s): + if all(c in '0123456789' for c in s): return int(s) - elif all(c in '0123456789.' for c in s): + if all(c in '0123456789.' for c in s): return float(s) - else: - return bytestring.parsebytes(s) + if s == 'now': + return now().timestamp() + + nowdelta = re.search(r'now((?:\+|-)\d+(?:\.\d*)?)', s) + if nowdelta: + nowdelta = nowdelta.group(1) + return now().timestamp() + float(nowdelta) + + return bytestring.parsebytes(s) def read_filebytes( filepath,