Commit 95587e2e authored by alan's avatar alan
Browse files

fixed time calc

parent 3f1e5f19
......@@ -55,4 +55,4 @@ crypto_pkey = b"It's really ten years into the future."
#mongodb_pass =
# logging server
labtool_url = "http://localhost:3939"
\ No newline at end of file
labtool_url = "http://linuxremote3.bucknell.edu:3939"
\ No newline at end of file
......@@ -20,13 +20,13 @@ def reset_limits(cmd, username, labstr):
return r.json()
def is_rate_limited(cmd="test", short=3, max=10, short_period=timedelta(minutes=15), **kwargs):
def is_rate_limited(cmd="test", short=3, max_calls=10, short_period=timedelta(minutes=15), **kwargs):
""""Returns true if this call exceeds the rate limits for the given kwargs
Arguments
---------
short is the maximum number of calls in the short_period.
max is the maximum number of calls ever.
short is the maximum number of calls in the short_period.
max_calls is the maximum number of calls ever.
"""
# add to kwargs
kwargs['cmd'] = cmd
......@@ -54,19 +54,19 @@ def is_rate_limited(cmd="test", short=3, max=10, short_period=timedelta(minutes=
#print(f"have {len(dates)}, short are {len(sh_dates)}")
#print([str(now-x) for x in dates])
if len(dates) >= max:
error(f"Maximum {cmd} limit ({max}) reached.")
if len(dates) >= max_calls:
error(f"Maximum {cmd} limit ({max_calls}) reached.")
return True
if len(sh_dates) >= short:
error(f"Maximum {cmd} limit ({short}) in the last {short_period.total_seconds()/60} minutes reached.")
error(f"You can try again in {short_period - (now-dates[0])}.")
error(f"You can try again in {short_period - (now - max(dates))}.")
return True
if len(sh_dates) > 0:
warn(f"You have already used {len(sh_dates)} of {short} checks in the last {short_period.total_seconds()/60} minutes!")
if len(dates) >= max / 2:
warn(f"You have already used {len(dates)} of {max} total checks!")
if len(dates) >= max_calls / 2:
warn(f"You have already used {len(dates)} of {max_calls} total checks!")
return False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment