fix: handle zero notifications

This commit is contained in:
Timothy Quilling 2023-07-02 23:51:46 -04:00
parent 93d5b503af
commit 47e8b485a5

View file

@ -795,12 +795,30 @@ def get_paginated_mastodon(url, max, headers = {}, timeout = 0, max_tries = 5):
if(isinstance(max, int)): if(isinstance(max, int)):
while len(result) < max and 'next' in response.links: while len(result) < max and 'next' in response.links:
response = get(response.links['next']['url'], headers, timeout, max_tries) response = get(response.links['next']['url'], headers, timeout, max_tries)
result = result + response.json() if response.status_code != 200:
raise Exception(
f"Error getting URL {response.url}. \
Status code: {response.status_code}"
)
response_json = response.json()
if isinstance(response_json, list):
result += response_json
else:
break
else: else:
while parser.parse(result[-1]['created_at']) >= max and 'next' in response.links: while result and parser.parse(result[-1]['created_at']) >= max \
and 'next' in response.links:
response = get(response.links['next']['url'], headers, timeout, max_tries) response = get(response.links['next']['url'], headers, timeout, max_tries)
result = result + response.json() if response.status_code != 200:
raise Exception(
f"Error getting URL {response.url}. \
Status code: {response.status_code}"
)
response_json = response.json()
if isinstance(response_json, list):
result += response_json
else:
break
return result return result