fix: handle zero notifications
This commit is contained in:
parent
93d5b503af
commit
47e8b485a5
1 changed files with 22 additions and 4 deletions
|
@ -795,12 +795,30 @@ def get_paginated_mastodon(url, max, headers = {}, timeout = 0, max_tries = 5):
|
|||
if(isinstance(max, int)):
|
||||
while len(result) < max and 'next' in response.links:
|
||||
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:
|
||||
while parser.parse(result[-1]['created_at']) >= max and 'next' in response.links:
|
||||
break
|
||||
else:
|
||||
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)
|
||||
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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue