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.
This commit is contained in:
voussoir 2022-07-23 00:13:40 -07:00
parent f8b1cd9178
commit df5870502a
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -347,14 +347,21 @@ def parse_unit_string(s) -> typing.Union[int, float, None]:
if ':' in s: if ':' in s:
return hms.hms_to_seconds(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) return int(s)
elif all(c in '0123456789.' for c in s): if all(c in '0123456789.' for c in s):
return float(s) return float(s)
else: if s == 'now':
return bytestring.parsebytes(s) 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( def read_filebytes(
filepath, filepath,