Merge pull request #61 from Teqed/fix/crash-on-zero-notifications

fix: handle zero notifications
This commit is contained in:
Michael 2023-07-03 07:02:16 +01:00 committed by GitHub
commit 4dc41ee02c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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: 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) 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