This commit is contained in:
Daniel Hnyk 2022-01-20 09:12:26 +01:00
parent 6c15fa1294
commit 594cf0f362

View file

@ -33,6 +33,7 @@ def handle_print(text, response_url=None):
else:
post_response(response_url, text)
# slack api (OAuth 2.0) now requires auth tokens in HTTP Authorization header
# instead of passing it as a query parameter
try:
@ -41,9 +42,11 @@ except KeyError:
handle_print("Missing SLACK_USER_TOKEN in environment variables", response_url)
sys.exit(1)
def _get_data(url, params):
return requests.get(url, headers=HEADERS, params=params)
def get_data(url, params):
"""Naively deals with throttling"""
@ -60,10 +63,13 @@ def get_data(url, params):
else:
retry_after = int(r.headers["Retry-After"]) # seconds to wait
sleep_time = retry_after + ADDITIONAL_SLEEP_TIME
print(f"Got throttled for {retry_after} seconds ({attempt}x). Sleeping for {sleep_time}")
print(
f"Got throttled for {retry_after} seconds ({attempt}x). Sleeping for {sleep_time}"
)
sleep(sleep_time)
return r
# pagination handling